From c57f632ef13f0b36bfb14ef8d55f9c111d3ee10a Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Thu, 2 Dec 2010 13:33:53 +0100 Subject: [PATCH] fcoemon: Small fixes for abstract sockets For abstract sockets we need to calculate the address length correctly so as not to be confused with trailing characters. And we don't need to unlink anything here. Signed-off-by: Hannes Reinecke diff --git a/fcoemon.c b/fcoemon.c index dbde71f..a8cdfc6 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -1190,6 +1190,7 @@ static int fcm_dcbd_connect(void) int fd; struct sockaddr_un dest; struct sockaddr_un *lp; + socklen_t addrlen; ASSERT(fcm_clif->cl_fd < 0); fd = socket(PF_UNIX, SOCK_DGRAM, 0); @@ -1204,7 +1205,8 @@ static int fcm_dcbd_connect(void) lp->sun_path[0] = '\0'; snprintf(&lp->sun_path[1], sizeof(lp->sun_path) - 1, CLIF_LOCAL_SUN_PATH, LLDP_CLIF_SOCK, getpid()); - rc = bind(fd, (struct sockaddr *)lp, sizeof(*lp)); + addrlen = sizeof(sa_family_t) + strlen(lp->sun_path + 1) + 1; + rc = bind(fd, (struct sockaddr *)lp, addrlen); if (rc < 0) { FCM_LOG_ERR(errno, "clif bind failed"); close(fd); @@ -1216,10 +1218,10 @@ static int fcm_dcbd_connect(void) dest.sun_path[0] = '\0'; snprintf(&dest.sun_path[1], sizeof(dest.sun_path) - 1, "%s", LLDP_CLIF_SOCK); - rc = connect(fd, (struct sockaddr *)&dest, sizeof(dest)); + addrlen = sizeof(sa_family_t) + strlen(dest.sun_path + 1) + 1; + rc = connect(fd, (struct sockaddr *)&dest, addrlen); if (rc < 0) { FCM_LOG_ERR(errno, "Failed to connect to lldpad"); - unlink(lp->sun_path); close(fd); return 0; }