int ret;
- /*
- As described bellow, when you have multiple interfaces, this forces the packet
- to go to a particular interface.
- */
+ /* as described bellow, when you have multiple interfaces, this
+ * forces the packet to go to a particular interface
+ */
ret = setsockopt(nga->sock, SOL_SOCKET, SO_BINDTODEVICE, nga->iface, strlen(nga->iface) + 1);
if (ret < 0) {
perror("setsockopt(SO_BINDTODEVICE)");
return ret;
}
- /*
- If the switch's IP is not in your network range, for instance because you do
- not have DHCP enabled or you started the switch after it, this allows to
- bypass the routing tables and consider every address is directly reachable on
- the interface.
- */
+ /* if the switch's IP is not in your network range, for instance
+ * because you do not have DHCP enabled or you started the switch
+ * after your DHCP server, this allows to bypass the routing tables
+ * and consider every address is directly reachable on the interface
+ */
ret = 1;
ret = setsockopt(nga->sock, SOL_SOCKET, SO_DONTROUTE, &ret, sizeof(ret));
if (ret <0) {
}
-int updateTimeout (struct ngadmin *nga)
-{
- int ret;
-
-
- /* specify receive timeout */
- ret = setsockopt(nga->sock, SOL_SOCKET, SO_RCVTIMEO, &nga->timeout, sizeof(struct timeval));
- if (ret < 0) {
- perror("setsockopt(SO_RCVTIMEO)");
- return ret;
- }
-
-
- return 0;
-}
-
-
static int checkErrorCode (const struct nsdp_cmd *nc)
{
switch (nc->error) {
+ case 0:
+ return ERR_OK;
+
case ERROR_DENIED:
return (nc->attr_error == ATTR_PASSWORD) ? ERR_BADPASS : ERR_DENIED;
return ERR_INVARG;
default:
- return ERR_OK;
+ return ERR_UNKNOWN;
}
}
memcpy(&nc->client_mac, &nga->localmac, ETH_ALEN);
nc->remote_addr.sin_family = AF_INET;
nc->remote_addr.sin_port = htons(SWITCH_PORT);
- if (sa != NULL) {
+ if (sa != NULL)
memcpy(&nc->switch_mac, &sa->mac, ETH_ALEN);
- nc->ports = sa->ports;
- }
/* destination address selection */
if (sa != NULL && !nga->keepbroad)
memcpy(&nc->client_mac, &nga->localmac, ETH_ALEN);
nc->remote_addr.sin_family = AF_INET;
nc->remote_addr.sin_port = htons(SWITCH_PORT);
- if (sa != NULL) {
+ if (sa != NULL)
memcpy(&nc->switch_mac, &sa->mac, ETH_ALEN);
- nc->ports = sa->ports;
- }
/* set filter on switch IP */
if (sa == NULL)
i = sendNsdpPacket(nga->sock, &nc, attr);
/* the list will be filled again by recvNgPacket
- but normally it will be still empty */
+ * but normally it will be still empty
+ */
clearList(attr, (void(*)(void*))freeAttr);
if (i >= 0) {
break;
case ATTR_DHCP:
- sa->nc.dhcp = (ntohs(*(unsigned short*)at->data) == 1);
+ /* Note: DHCP attribute is special, it is 2 two bytes long when sent
+ * by the switch but only 1 byte long when sent by the client
+ */
+ sa->nc.dhcp = (at->size == 2) && ((*(unsigned short*)at->data) == 1);
break;
case ATTR_FIRM_VER: