@@ -50,9 +50,7 @@ Module interface:
5050 specifying the ethernet interface and an integer specifying
5151 the Ethernet protocol number to be received. For example:
5252 ("eth0",0x1234). Optional 3rd,4th,5th elements in the tuple
53- specify packet-type and ha-type/addr -- these are ignored by
54- networking code, but accepted since they are returned by the
55- getsockname() method.
53+ specify packet-type and ha-type/addr.
5654
5755Local naming conventions:
5856
@@ -1223,10 +1221,12 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
12231221 int protoNumber ;
12241222 int hatype = 0 ;
12251223 int pkttype = 0 ;
1226- char * haddr ;
1224+ char * haddr = NULL ;
1225+ unsigned int halen = 0 ;
12271226
1228- if (!PyArg_ParseTuple (args , "si|iis" , & interfaceName ,
1229- & protoNumber , & pkttype , & hatype , & haddr ))
1227+ if (!PyArg_ParseTuple (args , "si|iis#" , & interfaceName ,
1228+ & protoNumber , & pkttype , & hatype ,
1229+ & haddr , & halen ))
12301230 return 0 ;
12311231 strncpy (ifr .ifr_name , interfaceName , sizeof (ifr .ifr_name ));
12321232 ifr .ifr_name [(sizeof (ifr .ifr_name ))- 1 ] = '\0' ;
@@ -1240,6 +1240,15 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
12401240 addr -> sll_ifindex = ifr .ifr_ifindex ;
12411241 addr -> sll_pkttype = pkttype ;
12421242 addr -> sll_hatype = hatype ;
1243+ if (halen > 8 ) {
1244+ PyErr_SetString (PyExc_ValueError ,
1245+ "Hardware address must be 8 bytes or less" );
1246+ return 0 ;
1247+ }
1248+ if (halen != 0 ) {
1249+ memcpy (& addr -> sll_addr , haddr , halen );
1250+ }
1251+ addr -> sll_halen = halen ;
12431252 * addr_ret = (struct sockaddr * ) addr ;
12441253 * len_ret = sizeof * addr ;
12451254 return 1 ;
0 commit comments