浏览代码

Added encode_ip_ip6 function needed by TLV 64.1 and 64.2

AdrianSimionov 10 年之前
父节点
当前提交
b1e2d536b8
共有 3 个文件被更改,包括 26 次插入3 次删除
  1. 23 1
      src/docsis_encode.c
  2. 1 0
      src/docsis_encode.h
  3. 2 2
      src/docsis_symtable.h

+ 23 - 1
src/docsis_encode.c

@@ -180,7 +180,7 @@ int encode_ip6( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
   helper = (union t_val *) tval;
 
   if ( !inet_pton(AF_INET6, helper->strval, &in) ) {
-	fprintf(stderr,  "Invalid IP address %s at line %d", helper->strval, line );
+	fprintf(stderr,  "Invalid IP address %s at line %d\n", helper->strval, line );
 	exit (-1);
   }
 #ifdef DEBUG
@@ -191,6 +191,28 @@ int encode_ip6( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
   return ( sizeof(struct in6_addr));
 }
 
+int encode_ip_ip6( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
+{
+  struct in6_addr in6;
+  struct in_addr in;
+  union t_val *helper; /* We only use this to cast the void* we receive to what we think it should be */
+
+  helper = (union t_val *) tval;
+
+  if ( inet_pton(AF_INET6, helper->strval, &in6) ) {
+    memcpy ( buf, &in6, sizeof(struct in6_addr));
+    free(helper->strval);
+    return ( sizeof(struct in6_addr));
+  } else if ( inet_aton ( helper->strval, &in) ) {
+    memcpy ( buf, &in, sizeof(struct in_addr));
+    free(helper->strval);
+    return ( sizeof(struct in_addr));    
+  } else {
+    fprintf(stderr, "Invalid IP address %s at line %d\n", helper->strval, line );
+    exit (-1);
+  }
+}
+
 int encode_ether ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 {
 int retval; 	     /* return value of inet_aton */

+ 1 - 0
src/docsis_encode.h

@@ -30,6 +30,7 @@ int encode_ushort 	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
 int encode_uchar  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ip     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ip6     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
+int encode_ip_ip6  	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ether	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_dual_qtag	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_dual_int	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );

+ 2 - 2
src/docsis_symtable.h

@@ -418,8 +418,8 @@ symbol_type symtable[NUM_IDENTIFIERS] =  {
 
 { 341,    "CMTSStaticMulticastSessionEncodings",  64,  0,      (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 64 MULPIv3.0-I24 Annex C.1.1.27 */
 /* TODO For TLV 64.1 and 64.2 encoding as IPv4 is a temporary solution, another encoder needs to be created to support both IPv4 and IPv6 */
-{ 342,    "CMTSStaticMulticastSessionGroup",   1,      341,    (encode_ip),             (decode_ip_ip6),         0,           0             }, /* TLV 64.1 MULPIv3.0-I24 Annex C.1.1.27.1 */
-{ 343,    "CMTSStaticMulticastSessionSource",  2,      341,    (encode_ip),             (decode_ip_ip6),         0,           0             }, /* TLV 64.2 MULPIv3.0-I24 Annex C.1.1.27.2 */
+{ 342,    "CMTSStaticMulticastSessionGroup",   1,      341,    (encode_ip_ip6),         (decode_ip_ip6),         0,           0             }, /* TLV 64.1 MULPIv3.0-I24 Annex C.1.1.27.1 */
+{ 343,    "CMTSStaticMulticastSessionSource",  2,      341,    (encode_ip_ip6),         (decode_ip_ip6),         0,           0             }, /* TLV 64.2 MULPIv3.0-I24 Annex C.1.1.27.2 */
 { 344,    "CMTSStaticMulticastSessionCMIM",    3,      341,    (encode_hexstr),         (decode_hexstr),         0,           0             }, /* TLV 64.3 MULPIv3.0-I24 Annex C.1.1.27.3 */
 
 /* eRouter TLVs */