Date: Mon, 30 Aug 2004 00:52:35 -0400 From: Skip Ford <skip.ford@verizon.net> To: Dennis George <easyeinfo@yahoo.com> Cc: freebsd-hackers@freebsd.org Subject: Re: Finding MTU Message-ID: <20040830045235.GA587@lucy.pool-70-17-33-17.pskn.east.verizon.net> In-Reply-To: <20040830025527.88596.qmail@web53908.mail.yahoo.com> References: <20040830025527.88596.qmail@web53908.mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Dennis George wrote: > Can anybody tell me how to find the MTU (Maximum Transmitting > Unit) in freeBSD programatically... The full source for ifconfig(8) is available. No need to ask anyone... http://www.freebsd.org/cgi/cvsweb.cgi/src/sbin/ifconfig/ifconfig.c?rev=1.106&content-type=text/x-cvsweb-markup However, here's a small program, probably taken from the sources above at some point, that prints the MTU for ed0. #include <sys/ioctl.h> #include <sys/types.h> #include <sys/socket.h> #include <net/if.h> #include <err.h> #include <stdio.h> #include <string.h> #include <unistd.h> int main(void) { int s, af = AF_INET; char *name = "ed0"; struct ifreq ifr; if ((s = socket(af, SOCK_DGRAM, 0)) < 0) err(1, "socket"); ifr.ifr_addr.sa_family = AF_INET; strcpy(ifr.ifr_name, name); if (ioctl(s, SIOCGIFMTU, (caddr_t)&ifr) < 0) warn("ioctl (get mtu)"); fprintf(stdout, "MTU of %s is %d.\n", name, ifr.ifr_mtu); close(s); return(0); } -- Skip
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040830045235.GA587>