~ubuntu-branches/ubuntu/jaunty/xorp/jaunty

« back to all changes in this revision

Viewing changes to libcomm/comm_sock.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Calhariz, Javier Fernandez-Sanguino, Jose Calhariz
  • Date: 2008-01-23 01:24:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123012437-7l2u9r0k8e7op8st
Tags: 1.5~cvs.20080128-1
[ Javier Fernandez-Sanguino ]
* Update to latest CVS contents
* Modify debian/rules to prevent autobuilders from building 
  the binary-independent components: (Closes: #441121)
  - Create a new Build-Depends-Indep with all the TeX
  components used to build documentation
  - Since autobuilders call build, which in turns calls build-indep, hack
    the debian rules file so that the documentation is only built if ps2pdf,
    dvips and pslatex are available. 
* Modify the init.d script:
  - restart action: Do not attempt to stop xorp if not running
  - stop function: fix errors in the script
  - add a try-restart action
  - restructure the init.d script, move the restart code to a function
  - review the use of echo calls and exit values
* Use, as examples, the new boot files at rtrmgr/config/

[ Jose Calhariz ]
* Add depends on ncurses-dev, I don't know why xorp use tigetstr
  function from curses.  This way the depends field change less between
  build environments.
* Removed pushd and popd commands from Makefile and replaced with cd
  commands, was a bashism and FTBFS (closes: #453637)
* debian/control converted to utf-8 (closes: #454026) (closes: #453485)
* init.d/xorp now returns 0 if disabled.
* Added Vcs-Browser and Vcs-Svn fields pointing to the repository of the
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 * SUCH DAMAGE.
32
32
 */
33
33
 
34
 
#ident "$XORP: xorp/libcomm/comm_sock.c,v 1.43 2007/08/22 01:10:02 pavlin Exp $"
 
34
#ident "$XORP: xorp/libcomm/comm_sock.c,v 1.44 2007/11/16 22:29:18 pavlin Exp $"
35
35
 
36
36
/*
37
37
 * COMM socket library lower `sock' level implementation.
86
86
const struct in6_addr in6addr_loopback = { { IN6ADDR_LOOPBACK_INIT } };
87
87
#endif
88
88
 
89
 
/**
90
 
 * comm_sock_open:
91
 
 * @domain: The domain of the socket (e.g., %AF_INET, %AF_INET6).
92
 
 * @type: The type of the socket (e.g., %SOCK_STREAM, %SOCK_DGRAM).
93
 
 * @protocol: The particular protocol to be used with the socket.
94
 
 * @is_blocking: If true, then the socket will be blocking, otherwise
95
 
 * non-blocking.
96
 
 *
97
 
 * Open a socket of domain = @domain, type = @type, and protocol = @protocol.
98
 
 * The sending and receiving buffer size are set, and the socket
99
 
 * itself is set with %TCP_NODELAY (if a TCP socket).
100
 
 *
101
 
 * Return value: The open socket on success, otherwise %XORP_BAD_SOCKET.
102
 
 **/
103
89
xsock_t
104
90
comm_sock_open(int domain, int type, int protocol, int is_blocking)
105
91
{
147
133
    return (sock);
148
134
}
149
135
 
150
 
/**
151
 
 * comm_sock_pair:
152
 
 *
153
 
 * Create a pair of connected sockets. The sockets will be created in
154
 
 * the blocking state by default, and with no additional socket options set.
155
 
 *
156
 
 * On Windows platforms, a domain of AF_UNIX, AF_INET, or AF_INET6 must
157
 
 * be specified. For the AF_UNIX case, the sockets created will actually
158
 
 * be in the AF_INET domain. The protocol field is ignored.
159
 
 *
160
 
 * On UNIX, this function simply wraps the socketpair() system call.
161
 
 *
162
 
 * XXX: There may be UNIX platforms lacking socketpair() where we
163
 
 * have to emulate it.
164
 
 *
165
 
 * @param domain the domain of the socket (e.g., AF_INET, AF_INET6).
166
 
 * @param type the type of the socket (e.g., SOCK_STREAM, SOCK_DGRAM).
167
 
 * @param protocol the particular protocol to be used with the socket.
168
 
 * @param sv pointer to an array of two xsock_t handles to receive the
169
 
 *        allocated socket pair.
170
 
 * @return XORP_OK on success, otherwise XORP_ERROR.
171
 
 **/
172
136
int
173
137
comm_sock_pair(int domain, int type, int protocol, xsock_t sv[2])
174
138
{
313
277
#endif /* HOST_OS_WINDOWS */
314
278
}
315
279
 
316
 
/**
317
 
 * comm_sock_bind4:
318
 
 * @sock: The socket to bind.
319
 
 * @my_addr: The address to bind to (in network order).
320
 
 * If it is NULL, will bind to `any' local address.
321
 
 * @my_port: The port to bind to (in network order).
322
 
 *
323
 
 * Bind an IPv4 socket to an address and a port.
324
 
 *
325
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
326
 
 **/
327
280
int
328
281
comm_sock_bind4(xsock_t sock, const struct in_addr *my_addr,
329
282
                unsigned short my_port)
363
316
    return (XORP_OK);
364
317
}
365
318
 
366
 
/**
367
 
 * comm_sock_bind6:
368
 
 * @sock: The socket to bind.
369
 
 * @my_addr: The address to bind to (in network order).
370
 
 * If it is NULL, will bind to `any' local address.
371
 
 * @my_port: The port to bind to (in network order).
372
 
 *
373
 
 * Bind an IPv6 socket to an address and a port.
374
 
 *
375
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
376
 
 **/
377
319
int
378
320
comm_sock_bind6(xsock_t sock, const struct in6_addr *my_addr,
379
 
                unsigned short my_port)
 
321
                unsigned int my_ifindex, unsigned short my_port)
380
322
{
381
323
#ifdef HAVE_IPV6
382
324
    int family;
400
342
        memcpy(&sin6_addr.sin6_addr, my_addr, sizeof(sin6_addr.sin6_addr));
401
343
    else
402
344
        memcpy(&sin6_addr.sin6_addr, &in6addr_any, sizeof(sin6_addr.sin6_addr));
403
 
 
404
 
    sin6_addr.sin6_scope_id = 0;                /* XXX: unused (?)           */
 
345
    if (IN6_IS_ADDR_LINKLOCAL(&sin6_addr.sin6_addr))
 
346
        sin6_addr.sin6_scope_id = my_ifindex;
 
347
    else
 
348
        sin6_addr.sin6_scope_id = 0;
405
349
 
406
350
    if (bind(sock, (struct sockaddr *)&sin6_addr, sizeof(sin6_addr)) < 0) {
407
351
        char addr_str[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
418
362
 
419
363
    return (XORP_OK);
420
364
#else /* ! HAVE_IPV6 */
421
 
    comm_sock_no_ipv6("comm_sock_bind6", sock, my_addr, my_port);
 
365
    comm_sock_no_ipv6("comm_sock_bind6", sock, my_addr, my_ifindex, my_port);
422
366
    return (XORP_ERROR);
423
367
#endif /* ! HAVE_IPV6 */
424
368
}
425
369
 
426
 
/**
427
 
 * Bind a socket (IPv4 or IPv6) to an address and a port.
428
 
 *
429
 
 * @param sock the socket to bind.
430
 
 * @param sin agnostic sockaddr containing the local address (If it is
431
 
 * NULL, will bind to `any' local address.)  and the local port to
432
 
 * bind to all in network order.
433
 
 * @return XORP_OK on success, otherwise XORP_ERROR.
434
 
 */
435
370
int
436
371
comm_sock_bind(xsock_t sock, const struct sockaddr *sin)
437
372
{
446
381
    case AF_INET6:
447
382
        {
448
383
            const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)((const void *)sin);
449
 
            return comm_sock_bind6(sock, &sin6->sin6_addr, sin6->sin6_port);
 
384
            return comm_sock_bind6(sock, &sin6->sin6_addr, sin6->sin6_scope_id,
 
385
                                   sin6->sin6_port);
450
386
        }
451
387
        break;
452
388
#endif /* HAVE_IPV6 */
460
396
    return XORP_ERROR;
461
397
}
462
398
 
463
 
/**
464
 
 * comm_sock_join4:
465
 
 * @sock: The socket to join the group.
466
 
 * @mcast_addr: The multicast address to join.
467
 
 * @my_addr: The local unicast address of an interface to join.
468
 
 * If it is NULL, the interface is chosen by the kernel.
469
 
 *
470
 
 * Join an IPv4 multicast group on a socket (and an interface).
471
 
 *
472
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
473
 
 **/
474
399
int
475
400
comm_sock_join4(xsock_t sock, const struct in_addr *mcast_addr,
476
401
                const struct in_addr *my_addr)
514
439
    return (XORP_OK);
515
440
}
516
441
 
517
 
/**
518
 
 * comm_sock_join6:
519
 
 * @sock: The socket to join the group.
520
 
 * @mcast_addr: The multicast address to join.
521
 
 * @my_ifindex: The local unicast interface index to join.
522
 
 * If it is 0, the interface is chosen by the kernel.
523
 
 *
524
 
 * Join an IPv6 multicast group on a socket (and an interface).
525
 
 *
526
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
527
 
 **/
528
442
int
529
443
comm_sock_join6(xsock_t sock, const struct in6_addr *mcast_addr,
530
444
                unsigned int my_ifindex)
563
477
#endif /* ! HAVE_IPV6 */
564
478
}
565
479
 
566
 
/**
567
 
 * comm_sock_leave4:
568
 
 * @sock: The socket to leave the group.
569
 
 * @mcast_addr: The multicast address to leave.
570
 
 * @my_addr: The local unicast address of an interface to leave.
571
 
 * If it is NULL, the interface is chosen by the kernel.
572
 
 *
573
 
 * Leave an IPv4 multicast group on a socket (and an interface).
574
 
 *
575
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
576
 
 **/
577
480
int
578
481
comm_sock_leave4(xsock_t sock, const struct in_addr *mcast_addr,
579
482
                const struct in_addr *my_addr)
617
520
    return (XORP_OK);
618
521
}
619
522
 
620
 
/**
621
 
 * comm_sock_leave6:
622
 
 * @sock: The socket to leave the group.
623
 
 * @mcast_addr: The multicast address to leave.
624
 
 * @my_ifindex: The local unicast interface index to leave.
625
 
 * If it is 0, the interface is chosen by the kernel.
626
 
 *
627
 
 * Leave an IPv6 multicast group on a socket (and an interface).
628
 
 *
629
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
630
 
 **/
631
523
int
632
524
comm_sock_leave6(xsock_t sock, const struct in6_addr *mcast_addr,
633
525
                unsigned int my_ifindex)
666
558
#endif /* ! HAVE_IPV6 */
667
559
}
668
560
 
669
 
/**
670
 
 * Connect to a remote IPv4 address.
671
 
 *
672
 
 * Note that we can use this function not only for TCP, but for UDP sockets
673
 
 * as well.
674
 
 *
675
 
 * @param sock the socket to use to connect.
676
 
 * @param remote_addr the remote address to connect to.
677
 
 * @param remote_port the remote port to connect to.
678
 
 * @param is_blocking if true, the socket is blocking, otherwise non-blocking.
679
 
 * @param in_progress if the socket is non-blocking and the connect cannot be
680
 
 * completed immediately, then the referenced value is set to 1, and the
681
 
 * return value is XORP_ERROR. For all other errors or if the non-blocking
682
 
 * socket was connected, the referenced value is set to 0. If the return value
683
 
 * is XORP_OK or if the socket is blocking, then the return value is undefined.
684
 
 * @return XORP_OK on success, otherwise XORP_ERROR.
685
 
 */
686
561
int
687
562
comm_sock_connect4(xsock_t sock, const struct in_addr *remote_addr,
688
563
                   unsigned short remote_port, int is_blocking,
738
613
    return (XORP_OK);
739
614
}
740
615
 
741
 
/**
742
 
 * Connect to a remote IPv6 address.
743
 
 *
744
 
 * Note that we can use this function not only for TCP, but for UDP sockets
745
 
 * as well.
746
 
 *
747
 
 * @param sock the socket to use to connect.
748
 
 * @param remote_addr the remote address to connect to.
749
 
 * @param remote_port the remote port to connect to.
750
 
 * @param is_blocking if true, the socket is blocking, otherwise non-blocking.
751
 
 * @param in_progress if the socket is non-blocking and the connect cannot be
752
 
 * completed immediately, then the referenced value is set to 1, and the
753
 
 * return value is XORP_ERROR. For all other errors or if the non-blocking
754
 
 * socket was connected, the referenced value is set to 0. If the return value
755
 
 * is XORP_OK or if the socket is blocking, then the return value is undefined.
756
 
 * @return XORP_OK on success, otherwise XORP_ERROR.
757
 
 */
758
616
int
759
617
comm_sock_connect6(xsock_t sock, const struct in6_addr *remote_addr,
760
618
                   unsigned short remote_port, int is_blocking,
827
685
#endif /* ! HAVE_IPV6 */
828
686
}
829
687
 
830
 
/**
831
 
 * Connect to a remote address (IPv4 or IPv6).
832
 
 *
833
 
 * Note that we can use this function not only for TCP, but for UDP sockets
834
 
 * as well.
835
 
 *
836
 
 * @param sock the socket to use to connect.
837
 
 * @param sin agnostic sockaddr containing the local address (If it is
838
 
 * NULL, will bind to `any' local address.)  and the local port to
839
 
 * bind to all in network order.
840
 
 * @param is_blocking if true, the socket is blocking, otherwise non-blocking.
841
 
 * @param in_progress if the socket is non-blocking and the connect cannot be
842
 
 * completed immediately, then the referenced value is set to 1, and the
843
 
 * return value is XORP_ERROR. For all other errors or if the non-blocking
844
 
 * socket was connected, the referenced value is set to 0. If the return value
845
 
 * is XORP_OK or if the socket is blocking, then the return value is undefined.
846
 
 * @return XORP_OK on success, otherwise XORP_ERROR.
847
 
 */
848
688
int
849
689
comm_sock_connect(xsock_t sock, const struct sockaddr *sin, int is_blocking,
850
690
                  int *in_progress)
877
717
    return XORP_ERROR;
878
718
}
879
719
 
880
 
/**
881
 
 * comm_sock_accept:
882
 
 * @sock: The listening socket to accept on.
883
 
 *
884
 
 * Accept a connection on a listening socket.
885
 
 *
886
 
 * Return value: The accepted socket on success, otherwise %XORP_BAD_SOCKET.
887
 
 **/
888
720
xsock_t
889
721
comm_sock_accept(xsock_t sock)
890
722
{
917
749
    return (sock_accept);
918
750
}
919
751
 
920
 
/**
921
 
 * comm_sock_listen:
922
 
 * @sock: The socket to listen on.
923
 
 * @backlog: The maximum queue size for pending connections.
924
 
 *
925
 
 * Listen on a socket.
926
 
 *
927
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
928
 
 **/
929
752
int
930
753
comm_sock_listen(xsock_t sock, int backlog)
931
754
{
942
765
    return (XORP_OK);
943
766
}
944
767
 
945
 
/**
946
 
 * comm_sock_close:
947
 
 * @sock: The socket to close.
948
 
 *
949
 
 * Close a socket.
950
 
 *
951
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
952
 
 **/
953
768
int
954
769
comm_sock_close(xsock_t sock)
955
770
{
972
787
    return (XORP_OK);
973
788
}
974
789
 
975
 
/**
976
 
 * comm_set_nodelay:
977
 
 * @sock: The socket whose option we want to set/reset.
978
 
 * @val: If non-zero, the option will be set, otherwise will be reset.
979
 
 *
980
 
 * Set/reset the %TCP_NODELAY option on a TCP socket.
981
 
 *
982
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
983
 
 **/
984
790
int
985
791
comm_set_nodelay(xsock_t sock, int val)
986
792
{
996
802
    return (XORP_OK);
997
803
}
998
804
 
999
 
/**
1000
 
 * comm_set_reuseaddr:
1001
 
 * @sock: The socket whose option we want to set/reset.
1002
 
 * @val: If non-zero, the option will be set, otherwise will be reset.
1003
 
 *
1004
 
 * Set/reset the %SO_REUSEADDR option on a socket.
1005
 
 * Note: If the OS doesn't support this option, then %XORP_ERROR is returned.
1006
 
 *
1007
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
1008
 
 **/
1009
805
int
1010
806
comm_set_reuseaddr(xsock_t sock, int val)
1011
807
{
1030
826
#endif /* ! SO_REUSEADDR */
1031
827
}
1032
828
 
1033
 
/**
1034
 
 * comm_set_reuseport:
1035
 
 * @sock: The socket whose option we want to set/reset.
1036
 
 * @val: If non-zero, the option will be set, otherwise will be reset.
1037
 
 *
1038
 
 * Set/reset the %SO_REUSEPORT option on a socket.
1039
 
 * Note: If the OS doesn't support this option, then %XORP_OK is returned.
1040
 
 *
1041
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
1042
 
 **/
1043
829
int
1044
830
comm_set_reuseport(xsock_t sock, int val)
1045
831
{
1064
850
#endif /* ! SO_REUSEPORT */
1065
851
}
1066
852
 
1067
 
/**
1068
 
 * comm_set_loopback:
1069
 
 * @sock: The socket whose option we want to set/reset.
1070
 
 * @val: If non-zero, the option will be set, otherwise will be reset.
1071
 
 *
1072
 
 * Set/reset the multicast loopback option on a socket.
1073
 
 *
1074
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
1075
 
 **/
1076
853
int
1077
854
comm_set_loopback(xsock_t sock, int val)
1078
855
{
1096
873
#ifdef HAVE_IPV6
1097
874
    case AF_INET6:
1098
875
    {
1099
 
        u_int loop6 = val;
 
876
        unsigned int loop6 = val;
1100
877
 
1101
878
        if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
1102
879
                       XORP_SOCKOPT_CAST(&loop6), sizeof(loop6)) < 0) {
1118
895
    return (XORP_OK);
1119
896
}
1120
897
 
1121
 
/**
1122
 
 * comm_set_tcpmd5:
1123
 
 * @sock: The socket whose option we want to set/reset.
1124
 
 * @val: If non-zero, the option will be set, otherwise will be reset.
1125
 
 *
1126
 
 * Set/reset the %TCP_MD5SIG option on a TCP socket.
1127
 
 * Note: If the OS doesn't support this option, then %XORP_ERROR is returned.
1128
 
 *
1129
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
1130
 
 **/
1131
898
int
1132
899
comm_set_tcpmd5(xsock_t sock, int val)
1133
900
{
1152
919
#endif /* ! TCP_MD5SIG */
1153
920
}
1154
921
 
1155
 
/**
1156
 
 * comm_set_ttl:
1157
 
 * @sock: The socket whose TTL we want to set.
1158
 
 * @val: The TTL of the outgoing multicast packets.
1159
 
 *
1160
 
 * Set the TTL of the outgoing multicast packets on a socket.
1161
 
 *
1162
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
1163
 
 **/
1164
922
int
1165
923
comm_set_ttl(xsock_t sock, int val)
1166
924
{
1205
963
    return (XORP_OK);
1206
964
}
1207
965
 
1208
 
/**
1209
 
 * comm_set_iface4:
1210
 
 * @sock: The socket whose default multicast interface to set.
1211
 
 * @in_addr: The IPv4 address of the default interface to set.
1212
 
 * If @in_addr is NULL, the system will choose the interface each time
1213
 
 * a datagram is sent.
1214
 
 *
1215
 
 * Set default interface for IPv4 outgoing multicast on a socket.
1216
 
 *
1217
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
1218
 
 **/
1219
966
int
1220
967
comm_set_iface4(xsock_t sock, const struct in_addr *in_addr)
1221
968
{
1244
991
    return (XORP_OK);
1245
992
}
1246
993
 
1247
 
/**
1248
 
 * comm_set_iface6:
1249
 
 * @sock: The socket whose default multicast interface to set.
1250
 
 * @ifindex: The IPv6 interface index of the default interface to set.
1251
 
 * If @ifindex is 0, the system will choose the interface each time
1252
 
 * a datagram is sent.
1253
 
 *
1254
 
 * Set default interface for IPv6 outgoing multicast on a socket.
1255
 
 *
1256
 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
1257
 
 **/
1258
994
int
1259
 
comm_set_iface6(xsock_t sock, u_int ifindex)
 
995
comm_set_iface6(xsock_t sock, unsigned int my_ifindex)
1260
996
{
1261
997
#ifdef HAVE_IPV6
1262
998
    int family = comm_sock_get_family(sock);
1268
1004
    }
1269
1005
 
1270
1006
    if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_IF,
1271
 
                   XORP_SOCKOPT_CAST(&ifindex), sizeof(ifindex)) < 0) {
 
1007
                   XORP_SOCKOPT_CAST(&my_ifindex), sizeof(my_ifindex)) < 0) {
1272
1008
        _comm_set_serrno();
1273
 
        XLOG_ERROR("setsockopt IPV6_MULTICAST_IF for ifindex %d: %s",
1274
 
                   ifindex, comm_get_error_str(comm_get_last_error()));
 
1009
        XLOG_ERROR("setsockopt IPV6_MULTICAST_IF for interface index %d: %s",
 
1010
                   my_ifindex, comm_get_error_str(comm_get_last_error()));
1275
1011
        return (XORP_ERROR);
1276
1012
    }
1277
1013
 
1278
1014
    return (XORP_OK);
1279
1015
 
1280
1016
#else /* ! HAVE_IPV6 */
1281
 
    comm_sock_no_ipv6("comm_set_iface6", sock, ifindex);
 
1017
    comm_sock_no_ipv6("comm_set_iface6", sock, my_ifindex);
1282
1018
    return (XORP_ERROR);
1283
1019
#endif /* ! HAVE_IPV6 */
1284
1020
}
1285
1021
 
1286
 
/**
1287
 
 * comm_sock_set_sndbuf:
1288
 
 * @sock: The socket whose sending buffer size to set.
1289
 
 * @desired_bufsize: The preferred buffer size.
1290
 
 * @min_bufsize: The smallest acceptable buffer size.
1291
 
 *
1292
 
 * Set the sending buffer size of a socket.
1293
 
 *
1294
 
 * Return value: The successfully set buffer size on success,
1295
 
 * otherwise %XORP_ERROR.
1296
 
 **/
1297
1022
int
1298
1023
comm_sock_set_sndbuf(xsock_t sock, int desired_bufsize, int min_bufsize)
1299
1024
{
1337
1062
    return (desired_bufsize);
1338
1063
}
1339
1064
 
1340
 
/**
1341
 
 * comm_sock_set_rcvbuf:
1342
 
 * @sock: The socket whose receiving buffer size to set.
1343
 
 * @desired_bufsize: The preferred buffer size.
1344
 
 * @min_bufsize: The smallest acceptable buffer size.
1345
 
 *
1346
 
 * Set the receiving buffer size of a socket.
1347
 
 *
1348
 
 * Return value: The successfully set buffer size on success,
1349
 
 * otherwise %XORP_ERROR.
1350
 
 **/
1351
1065
int
1352
1066
comm_sock_set_rcvbuf(xsock_t sock, int desired_bufsize, int min_bufsize)
1353
1067
{
1391
1105
    return (desired_bufsize);
1392
1106
}
1393
1107
 
1394
 
/**
1395
 
 * comm_sock_get_family:
1396
 
 * @sock: The socket whose address family we need to get.
1397
 
 *
1398
 
 * Get the address family of a socket.
1399
 
 *
1400
 
 * Note: Idea taken from W. Stevens' UNPv1, 2e (pp 109).
1401
 
 *
1402
 
 * Return value: The address family on success, otherwise %XORP_ERROR.
1403
 
 **/
1404
1108
int
1405
1109
comm_sock_get_family(xsock_t sock)
1406
1110
{
1443
1147
#endif /* ! HOST_OS_WINDOWS */
1444
1148
}
1445
1149
 
1446
 
/**
1447
 
 * comm_sock_get_type:
1448
 
 * @sock: The socket whose type we need to get.
1449
 
 *
1450
 
 * Get the type of a socket.
1451
 
 * Examples of socket type are SOCK_STREAM for TCP, SOCK_DGRAM for UDP,
1452
 
 * and SOCK_RAW for raw protocol sockets.
1453
 
 *
1454
 
 * Return value: The socket type on success, otherwise %XORP_ERROR.
1455
 
 **/
1456
1150
int
1457
1151
comm_sock_get_type(xsock_t sock)
1458
1152
{
1471
1165
    return type;
1472
1166
}
1473
1167
 
1474
 
/**
1475
 
 * comm_sock_set_blocking:
1476
 
 *
1477
 
 * Set the blocking or non-blocking mode of an existing socket.
1478
 
 * @sock: The socket whose blocking mode is to be set.
1479
 
 * @is_blocking: If non-zero, then the socket will be blocking, otherwise
1480
 
 * non-blocking.
1481
 
 *
1482
 
 * Return value: XORP_OK on success, otherwise XORP_ERROR.
1483
 
 **/
1484
1168
int
1485
1169
comm_sock_set_blocking(xsock_t sock, int is_blocking)
1486
1170
{
1526
1210
    return (XORP_OK);
1527
1211
}
1528
1212
 
1529
 
/**
1530
 
 * comm_sock_is_connected:
1531
 
 * @psock: The socket whose connected state is to be queried.
1532
 
 * @is_connected: If the socket is in the connected state, then the
1533
 
 * referenced value is set to 1, otherwise it is set to 0.
1534
 
 *
1535
 
 * Determine if an existing socket is in the connected state.
1536
 
 *
1537
 
 * Return value: XORP_OK on success, otherwise XORP_ERROR.
1538
 
 **/
1539
1213
int
1540
1214
comm_sock_is_connected(xsock_t sock, int *is_connected)
1541
1215
{
1580
1254
    return (XORP_OK);
1581
1255
}
1582
1256
 
1583
 
/**
1584
 
 * comm_sock_no_ipv6:
1585
 
 *
1586
 
 * Log an error when an IPv6 specific method is called when IPv6 is
1587
 
 * not preset. Set an appropriate error code relevant to the platform
1588
 
 * we're running under.
1589
 
 *
1590
 
 * XXX This is currently done with knowledge of how the error code is
1591
 
 * internally stored, which is a design bug (we're not thread friendly).
1592
 
 *
1593
 
 * @param method C-style string denoting the ipv6 function called.
1594
 
 **/
1595
1257
void
1596
1258
comm_sock_no_ipv6(const char* method, ...)
1597
1259
{
1603
1265
    XLOG_ERROR("%s: IPv6 support not present.", method);
1604
1266
}
1605
1267
 
1606
 
/**
1607
 
 * _comm_set_serrno:
1608
 
 *
1609
 
 * Fetch the socket layer error code from the underlying system, clear
1610
 
 * the general error condition, and record it.
1611
 
 *
1612
 
 * XXX: Currently not thread-safe. Internal use only.
1613
 
 **/
1614
1268
void
1615
1269
_comm_set_serrno(void)
1616
1270
{