[Python-checkins] python/dist/src/Modules socketmodule.c, 1.294, 1.295

akuchling at users.sourceforge.net akuchling at users.sourceforge.net
Sun Jul 11 01:39:38 CEST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24420

Modified Files:
	socketmodule.c 
Log Message:
[Patch #947352 from Jason Andryuk] Add support for AF_PACKET hardware addresses

Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.294
retrieving revision 1.295
diff -C2 -d -r1.294 -r1.295
*** socketmodule.c	10 Jul 2004 14:19:21 -0000	1.294
--- socketmodule.c	10 Jul 2004 23:39:35 -0000	1.295
***************
*** 51,57 ****
    the Ethernet protocol number to be received. For example:
    ("eth0",0x1234).  Optional 3rd,4th,5th elements in the tuple
!   specify packet-type and ha-type/addr -- these are ignored by
!   networking code, but accepted since they are returned by the
!   getsockname() method.
  
  Local naming conventions:
--- 51,55 ----
    the Ethernet protocol number to be received. For example:
    ("eth0",0x1234).  Optional 3rd,4th,5th elements in the tuple
!   specify packet-type and ha-type/addr.
  
  Local naming conventions:
***************
*** 1224,1231 ****
  		int hatype = 0;
  		int pkttype = 0;
! 		char *haddr;
  
! 		if (!PyArg_ParseTuple(args, "si|iis", &interfaceName,
! 				      &protoNumber, &pkttype, &hatype, &haddr))
  			return 0;
  		strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name));
--- 1222,1231 ----
  		int hatype = 0;
  		int pkttype = 0;
! 		char *haddr = NULL;
! 		unsigned int halen = 0;
  
! 		if (!PyArg_ParseTuple(args, "si|iis#", &interfaceName,
! 				      &protoNumber, &pkttype, &hatype,
! 				      &haddr, &halen))
  			return 0;
  		strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name));
***************
*** 1241,1244 ****
--- 1241,1253 ----
  		addr->sll_pkttype = pkttype;
  		addr->sll_hatype = hatype;
+ 		if (halen > 8) {
+ 		  PyErr_SetString(PyExc_ValueError,
+ 				  "Hardware address must be 8 bytes or less");
+ 		  return 0;
+ 		}
+ 		if (halen != 0) {
+ 		  memcpy(&addr->sll_addr, haddr, halen);
+ 		}
+ 		addr->sll_halen = halen;
  		*addr_ret = (struct sockaddr *) addr;
  		*len_ret = sizeof *addr;



More information about the Python-checkins mailing list