[Python-checkins] CVS: python/dist/src/Modules socketmodule.c,1.134,1.135
Jeremy Hylton
jhylton@users.sourceforge.net
Fri, 02 Feb 2001 11:55:19 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv12336/Modules
Modified Files:
socketmodule.c
Log Message:
fix a couple last-minute bugs in the raw socket support
Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -C2 -r1.134 -r1.135
*** socketmodule.c 2001/02/02 03:23:09 1.134
--- socketmodule.c 2001/02/02 19:55:17 1.135
***************
*** 38,43 ****
specifying the ethernet interface and an integer specifying
the Ethernet protocol number to be received. For example:
! ("eth0",0x1234). Optional 3rd and 4th elements in the tuple
! specify packet-type and ha-type -- these are ignored by
networking code, but accepted since they are returned by the
getsockname() method.
--- 38,43 ----
specifying the ethernet interface and an integer specifying
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.
***************
*** 535,539 ****
/*ARGSUSED*/
static PyObject *
! makesockaddr(struct sockaddr *addr, int addrlen)
{
if (addrlen == 0) {
--- 535,539 ----
/*ARGSUSED*/
static PyObject *
! makesockaddr(int sockfd, struct sockaddr *addr, int addrlen)
{
if (addrlen == 0) {
***************
*** 576,593 ****
char *ifname = "";
struct ifreq ifr;
! int s;
! /* need a socket on which we can do an ioctl to look
! * up interface name from index, but only if index is
! * non-zero.
! */
! if (a->sll_ifindex
! && ((s = socket(AF_PACKET, SOCK_RAW, 0)) >= 0)) {
ifr.ifr_ifindex = a->sll_ifindex;
! if (ioctl(s, SIOCGIFNAME, &ifr) == 0)
ifname = ifr.ifr_name;
- close(s);
}
! return Py_BuildValue("shbh", ifname, ntohs(a->sll_protocol),
! a->sll_pkttype, a->sll_hatype);
}
#endif
--- 576,588 ----
char *ifname = "";
struct ifreq ifr;
! /* need to look up interface name give index */
! if (a->sll_ifindex) {
ifr.ifr_ifindex = a->sll_ifindex;
! if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0)
ifname = ifr.ifr_name;
}
! return Py_BuildValue("shbhs#", ifname, ntohs(a->sll_protocol),
! a->sll_pkttype, a->sll_hatype,
! a->sll_addr, a->sll_halen);
}
#endif
***************
*** 613,617 ****
static int
! getsockaddrarg(PySocketSockObject *s, PyObject *args, struct sockaddr **addr_ret, int *len_ret)
{
switch (s->sock_family) {
--- 608,613 ----
static int
! getsockaddrarg(PySocketSockObject *s, PyObject *args,
! struct sockaddr **addr_ret, int *len_ret)
{
switch (s->sock_family) {
***************
*** 672,683 ****
int hatype = 0;
int pkttype = 0;
! if (!PyArg_ParseTuple(args, "si|ii", &interfaceName,
! &protoNumber, &pkttype, &hatype))
return 0;
strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name));
ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0';
! if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr))
return 0;
addr = &(s->sock_addr.ll);
addr->sll_family = AF_PACKET;
--- 668,682 ----
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));
ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0';
! if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) {
! PyErr_SetFromErrno(PySocket_Error);
return 0;
+ }
addr = &(s->sock_addr.ll);
addr->sll_family = AF_PACKET;
***************
*** 780,788 ****
goto finally;
}
! if (!(addr = makesockaddr((struct sockaddr *) addrbuf, addrlen)))
goto finally;
! if (!(res = Py_BuildValue("OO", sock, addr)))
! goto finally;
finally:
--- 779,788 ----
goto finally;
}
! addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
! addrlen);
! if (addr == NULL)
goto finally;
! res = Py_BuildValue("OO", sock, addr);
finally:
***************
*** 1129,1133 ****
if (res < 0)
return PySocket_Err();
! return makesockaddr((struct sockaddr *) addrbuf, addrlen);
}
--- 1129,1133 ----
if (res < 0)
return PySocket_Err();
! return makesockaddr(s->sock_fd, (struct sockaddr *) addrbuf, addrlen);
}
***************
*** 1158,1162 ****
if (res < 0)
return PySocket_Err();
! return makesockaddr((struct sockaddr *) addrbuf, addrlen);
}
--- 1158,1162 ----
if (res < 0)
return PySocket_Err();
! return makesockaddr(s->sock_fd, (struct sockaddr *) addrbuf, addrlen);
}
***************
*** 1320,1324 ****
return NULL;
! if (!(addr = makesockaddr((struct sockaddr *)addrbuf, addrlen)))
goto finally;
--- 1320,1324 ----
return NULL;
! if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf, addrlen)))
goto finally;