Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6153b71a authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I57cb2003,I569d2b81,I01a10e36

* changes:
  libnetutils/packet.c - create socket with close-on-exec
  libnetutils/packet.c - fix a raw socket reception race
  libnetutils/packet.c - fix a socket leak on bind error
parents b7dd2935 39c26d63
Loading
Loading
Loading
Loading
+13 −16
Original line number Original line Diff line number Diff line
@@ -37,25 +37,22 @@


#include "dhcpmsg.h"
#include "dhcpmsg.h"


int fatal();
int fatal(const char*);


int open_raw_socket(const char *ifname __attribute__((unused)), uint8_t *hwaddr, int if_index)
int open_raw_socket(const char* ifname __unused, uint8_t hwaddr[ETH_ALEN], int if_index) {
{
    int s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
    int s;
    if (s < 0) return fatal("socket(PF_PACKET)");
    struct sockaddr_ll bindaddr;


    struct sockaddr_ll bindaddr = {
    if((s = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
            .sll_family = AF_PACKET,
        return fatal("socket(PF_PACKET)");
            .sll_protocol = htons(ETH_P_IP),
    }
            .sll_ifindex = if_index,

            .sll_halen = ETH_ALEN,
    memset(&bindaddr, 0, sizeof(bindaddr));
    };
    bindaddr.sll_family = AF_PACKET;
    bindaddr.sll_protocol = htons(ETH_P_IP);
    bindaddr.sll_halen = ETH_ALEN;
    memcpy(bindaddr.sll_addr, hwaddr, ETH_ALEN);
    memcpy(bindaddr.sll_addr, hwaddr, ETH_ALEN);
    bindaddr.sll_ifindex = if_index;


    if (bind(s, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
    if (bind(s, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
        close(s);
        return fatal("Cannot bind raw socket to interface");
        return fatal("Cannot bind raw socket to interface");
    }
    }


+3 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,9 @@
#ifndef _WIFI_PACKET_H_
#ifndef _WIFI_PACKET_H_
#define _WIFI_PACKET_H_
#define _WIFI_PACKET_H_


int open_raw_socket(const char *ifname, uint8_t *hwaddr, int if_index);
#include <linux/if_ether.h>

int open_raw_socket(const char* ifname, uint8_t hwaddr[ETH_ALEN], int if_index);
int send_packet(int s, int if_index, struct dhcp_msg *msg, int size,
int send_packet(int s, int if_index, struct dhcp_msg *msg, int size,
                uint32_t saddr, uint32_t daddr, uint32_t sport, uint32_t dport);
                uint32_t saddr, uint32_t daddr, uint32_t sport, uint32_t dport);
int receive_packet(int s, struct dhcp_msg *msg);
int receive_packet(int s, struct dhcp_msg *msg);