util.c (842620c7) util.c (69bb4bb4)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

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

28#include <unistd.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <stdlib.h>
32#include <netinet/in.h> /* struct in_addr */
33#include <netinet/dhcp.h>
34#include <signal.h>
35#include <sys/dlpi.h>
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

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

28#include <unistd.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <stdlib.h>
32#include <netinet/in.h> /* struct in_addr */
33#include <netinet/dhcp.h>
34#include <signal.h>
35#include <sys/dlpi.h>
36#include <sys/sockio.h>
37#include <sys/socket.h>
36#include <sys/socket.h>
38#include <errno.h>
39#include <net/route.h>
40#include <net/if_arp.h>
41#include <string.h>
42#include <dhcpmsg.h>
43#include <ctype.h>
44#include <netdb.h>
45#include <fcntl.h>
46#include <stdio.h>
47
48#include "states.h"
49#include "agent.h"
50#include "interface.h"
51#include "util.h"
52#include "packet.h"
37#include <net/route.h>
38#include <net/if_arp.h>
39#include <string.h>
40#include <dhcpmsg.h>
41#include <ctype.h>
42#include <netdb.h>
43#include <fcntl.h>
44#include <stdio.h>
45
46#include "states.h"
47#include "agent.h"
48#include "interface.h"
49#include "util.h"
50#include "packet.h"
53#include "defaults.h"
54
55/*
56 * this file contains utility functions that have no real better home
57 * of their own. they can largely be broken into six categories:
58 *
59 * o conversion functions -- functions to turn integers into strings,
60 * or to convert between units of a similar measure.
61 *

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

390 * int: any additional flags (besides RTF_STATIC and RTF_GATEWAY)
391 * output: int: 1 on success, 0 on failure
392 */
393
394static int
395update_default_route(const char *ifname, int type, struct in_addr *gateway_nbo,
396 int flags)
397{
51
52/*
53 * this file contains utility functions that have no real better home
54 * of their own. they can largely be broken into six categories:
55 *
56 * o conversion functions -- functions to turn integers into strings,
57 * or to convert between units of a similar measure.
58 *

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

387 * int: any additional flags (besides RTF_STATIC and RTF_GATEWAY)
388 * output: int: 1 on success, 0 on failure
389 */
390
391static int
392update_default_route(const char *ifname, int type, struct in_addr *gateway_nbo,
393 int flags)
394{
398 static int rtsock_fd = -1;
399 struct {
400 struct rt_msghdr rm_mh;
401 struct sockaddr_in rm_dst;
402 struct sockaddr_in rm_gw;
403 struct sockaddr_in rm_mask;
404 struct sockaddr_dl rm_ifp;
405 } rtmsg;
406
395 struct {
396 struct rt_msghdr rm_mh;
397 struct sockaddr_in rm_dst;
398 struct sockaddr_in rm_gw;
399 struct sockaddr_in rm_mask;
400 struct sockaddr_dl rm_ifp;
401 } rtmsg;
402
407 if (rtsock_fd == -1) {
408 rtsock_fd = socket(PF_ROUTE, SOCK_RAW, 0);
409 if (rtsock_fd == -1) {
410 dhcpmsg(MSG_ERR, "update_default_route: "
411 "cannot create routing socket");
412 return (0);
413 }
414 }
415
416 (void) memset(&rtmsg, 0, sizeof (rtmsg));
417 rtmsg.rm_mh.rtm_version = RTM_VERSION;
418 rtmsg.rm_mh.rtm_msglen = sizeof (rtmsg);
419 rtmsg.rm_mh.rtm_type = type;
420 rtmsg.rm_mh.rtm_pid = getpid();
421 rtmsg.rm_mh.rtm_flags = RTF_GATEWAY | RTF_STATIC | flags;
422 rtmsg.rm_mh.rtm_addrs = RTA_GATEWAY | RTA_DST | RTA_NETMASK | RTA_IFP;
423

--- 334 unchanged lines hidden ---
403 (void) memset(&rtmsg, 0, sizeof (rtmsg));
404 rtmsg.rm_mh.rtm_version = RTM_VERSION;
405 rtmsg.rm_mh.rtm_msglen = sizeof (rtmsg);
406 rtmsg.rm_mh.rtm_type = type;
407 rtmsg.rm_mh.rtm_pid = getpid();
408 rtmsg.rm_mh.rtm_flags = RTF_GATEWAY | RTF_STATIC | flags;
409 rtmsg.rm_mh.rtm_addrs = RTA_GATEWAY | RTA_DST | RTA_NETMASK | RTA_IFP;
410

--- 334 unchanged lines hidden ---