Deleted Added
full compact
ns.c (49653) ns.c (50186)
1/*-
2 * Copyright (c) 1998 Andrzej Bialecki
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 121 unchanged lines hidden (view full) ---

130 if (unp->sun_path[0] == 0)
131 strcpy(str, "(no pathname bound)");
132 else
133 snprintf(str, sizeof(str), "%s", unp->sun_path);
134 return(str);
135 }
136 case AF_LINK: {
137 struct sockaddr_dl *sdl = (struct sockaddr_dl *) sa;
1/*-
2 * Copyright (c) 1998 Andrzej Bialecki
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 121 unchanged lines hidden (view full) ---

130 if (unp->sun_path[0] == 0)
131 strcpy(str, "(no pathname bound)");
132 else
133 snprintf(str, sizeof(str), "%s", unp->sun_path);
134 return(str);
135 }
136 case AF_LINK: {
137 struct sockaddr_dl *sdl = (struct sockaddr_dl *) sa;
138 int l = sdl->sdl_nlen ;
139
138
140 if (l >= sizeof(str) )
141 l = sizeof(str) - 1 ;
142
143 if (l > 0) {
144 strncpy(str, &sdl->sdl_data[0], l);
145 str[l] = '\0';
146 } else
139 if (sdl->sdl_nlen > 0)
140 snprintf(str, sizeof(str), "%*s",
141 sdl->sdl_nlen, &sdl->sdl_data[0]);
142 else
147 snprintf(str, sizeof(str), "link#%d", sdl->sdl_index);
148 return(str);
149 }
150 default:
151 snprintf(str, sizeof(str), "sock_ntop: unknown AF_xxx: %d, len %d",
152 sa->sa_family, salen);
153 return(str);
154 }

--- 147 unchanged lines hidden (view full) ---

302 if_num=i;
303 if_table=(struct sockaddr **)calloc(i,sizeof(struct sockaddr));
304 ifm_table=(struct if_msghdr **)calloc(i,sizeof(struct if_msghdr));
305 if (iflag) {
306 printf("\nInterface table:\n");
307 printf("----------------\n");
308 printf("Name Mtu Network Address "
309 "Ipkts Ierrs Opkts Oerrs Coll\n");
143 snprintf(str, sizeof(str), "link#%d", sdl->sdl_index);
144 return(str);
145 }
146 default:
147 snprintf(str, sizeof(str), "sock_ntop: unknown AF_xxx: %d, len %d",
148 sa->sa_family, salen);
149 return(str);
150 }

--- 147 unchanged lines hidden (view full) ---

298 if_num=i;
299 if_table=(struct sockaddr **)calloc(i,sizeof(struct sockaddr));
300 ifm_table=(struct if_msghdr **)calloc(i,sizeof(struct if_msghdr));
301 if (iflag) {
302 printf("\nInterface table:\n");
303 printf("----------------\n");
304 printf("Name Mtu Network Address "
305 "Ipkts Ierrs Opkts Oerrs Coll\n");
310 i=0;
311 for(next=if_buf;next<lim;next+=ifm->ifm_msglen) {
306 }
307 i=0;
308 for(next=if_buf;next<lim;next+=ifm->ifm_msglen) {
312
313 ifm=(struct if_msghdr *)next;
314 if_table[i]=(struct sockaddr *)(ifm+1);
315 ifm_table[i]=ifm;
316
317 sa = if_table[i];
309
310 ifm=(struct if_msghdr *)next;
311 if_table[i]=(struct sockaddr *)(ifm+1);
312 ifm_table[i]=ifm;
313
314 sa = if_table[i];
318 if (sa->sa_family == AF_LINK) {
315 if (iflag && sa->sa_family == AF_LINK) {
319 struct sockaddr_dl *sdl = (struct sockaddr_dl *) sa;
320
321 printf("%-4s %-5d <Link> ",
322 sock_ntop(if_table[i], if_table[i]->sa_len),
323 ifm->ifm_data.ifi_mtu);
324 if ( sdl->sdl_alen == 6) {
325 unsigned char *p = sdl->sdl_data + sdl->sdl_nlen ;
326 printf("%02x:%02x:%02x:%02x:%02x:%02x ",

--- 4 unchanged lines hidden (view full) ---

331 ifm->ifm_data.ifi_ipackets,
332 ifm->ifm_data.ifi_ierrors,
333 ifm->ifm_data.ifi_opackets,
334 ifm->ifm_data.ifi_oerrors,
335 ifm->ifm_data.ifi_collisions
336 );
337 }
338 i++;
316 struct sockaddr_dl *sdl = (struct sockaddr_dl *) sa;
317
318 printf("%-4s %-5d <Link> ",
319 sock_ntop(if_table[i], if_table[i]->sa_len),
320 ifm->ifm_data.ifi_mtu);
321 if ( sdl->sdl_alen == 6) {
322 unsigned char *p = sdl->sdl_data + sdl->sdl_nlen ;
323 printf("%02x:%02x:%02x:%02x:%02x:%02x ",

--- 4 unchanged lines hidden (view full) ---

328 ifm->ifm_data.ifi_ipackets,
329 ifm->ifm_data.ifi_ierrors,
330 ifm->ifm_data.ifi_opackets,
331 ifm->ifm_data.ifi_oerrors,
332 ifm->ifm_data.ifi_collisions
333 );
334 }
335 i++;
339 }
340 }
341 if (!rflag) {
342 free(rt_buf);
343 free(if_buf);
344 free(if_table);
345 free(ifm_table);
346 return(0);
347 }

--- 417 unchanged lines hidden ---
336 }
337 if (!rflag) {
338 free(rt_buf);
339 free(if_buf);
340 free(if_table);
341 free(ifm_table);
342 return(0);
343 }

--- 417 unchanged lines hidden ---