Properly initialize sockaddr_in struct in fast and dhcp plugins
authorTobias Brunner <tobias@strongswan.org>
Fri, 28 Sep 2012 14:03:09 +0000 (16:03 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 28 Sep 2012 14:28:46 +0000 (16:28 +0200)
src/libcharon/plugins/dhcp/dhcp_socket.c
src/libfast/smtp.c

index 104c71c..f469c5a 100644 (file)
@@ -648,7 +648,13 @@ METHOD(dhcp_socket_t, destroy, void,
 dhcp_socket_t *dhcp_socket_create()
 {
        private_dhcp_socket_t *this;
-       struct sockaddr_in src;
+       struct sockaddr_in src = {
+               .sin_family = AF_INET,
+               .sin_port = htons(DHCP_CLIENT_PORT),
+               .sin_addr = {
+                       .s_addr = INADDR_ANY,
+               },
+       };
        int on = 1;
        struct sock_filter dhcp_filter_code[] = {
                BPF_STMT(BPF_LD+BPF_B+BPF_ABS,
@@ -738,9 +744,6 @@ dhcp_socket_t *dhcp_socket_create()
                destroy(this);
                return NULL;
        }
-       src.sin_family = AF_INET;
-       src.sin_port = htons(DHCP_CLIENT_PORT);
-       src.sin_addr.s_addr = INADDR_ANY;
        if (bind(this->send, (struct sockaddr*)&src, sizeof(src)) == -1)
        {
                DBG1(DBG_CFG, "unable to bind DHCP send socket: %s", strerror(errno));
index 4118c74..1375c29 100644 (file)
@@ -136,7 +136,13 @@ METHOD(smtp_t, destroy, void,
 smtp_t *smtp_create()
 {
        private_smtp_t *this;
-       struct sockaddr_in addr;
+       struct sockaddr_in addr = {
+               .sin_family = AF_INET,
+               .sin_port = htons(25),
+               .sin_addr = {
+                       .s_addr = htonl(INADDR_LOOPBACK),
+               },
+       };
        int s;
 
        INIT(this,
@@ -153,9 +159,6 @@ smtp_t *smtp_create()
                free(this);
                return NULL;
        }
-       addr.sin_family = AF_INET;
-       addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-       addr.sin_port = htons(25);
        if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) < 0)
        {
                DBG1(DBG_LIB, "connecting to SMTP server failed: %s", strerror(errno));