From: Kevin Day Date: Thu, 6 Jul 2023 03:38:12 +0000 (-0500) Subject: Update: Socket improvements regarding structure and styling. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=90d0f47999fd5615f2f3550d688f63d49e590482;p=fll Update: Socket improvements regarding structure and styling. The f_socket_t structure has "struct sockaddr" as a pointer. This means mass allocation becomes less practical due to needing to create the actual "struct sockaddr" as needed. Implement an f_socket_address_t union that accepts the cost of less memory efficiency to improve the usability. This now allows for mixed types to be stored in the array without needing complicated code to manage different arrays. The caller will have to be responsible for properly setting the appropriate structure as needed. Organize the code styling to be more consistent with alphabetical ordering. I likely have some of the comments to update as well (a follow up commit will be necessary). --- diff --git a/level_0/f_network/c/network/common.h b/level_0/f_network/c/network/common.h index b78f3a2..aad4ba6 100644 --- a/level_0/f_network/c/network/common.h +++ b/level_0/f_network/c/network/common.h @@ -41,7 +41,6 @@ extern "C" { * macro_f_network_family_ip_4_or_6_t_*: * - initialize_1: Specifically initialize the IP address version 4. * - initialize_2: Specifically initialize the IP address version 6. - * - clear: Clear the union values. */ #ifndef _di_f_network_family_ip_4_or_6_t_ typedef union { @@ -53,10 +52,6 @@ extern "C" { #define macro_f_network_family_ip_4_or_6_t_initialize_1(v4) { .v4 = v4 } #define macro_f_network_family_ip_4_or_6_t_initialize_2(v6) { .v6 = v6 } - - #define f_network_family_ip_4_or_6_t_clear(family_ip_4_or_6) \ - family_ip_4_or_6.v4 = 0; \ - family_ip_4_or_6.v6 = 0; #endif // _di_f_network_family_ip_4_or_6_t_ /** diff --git a/level_0/f_socket/c/socket.c b/level_0/f_socket/c/socket.c index 54973d9..209556c 100644 --- a/level_0/f_socket/c/socket.c +++ b/level_0/f_socket/c/socket.c @@ -10,7 +10,7 @@ extern "C" { if (!socket) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - const int result = accept(id, socket->address, &socket->length); + const int result = accept(id, (struct sockaddr *) &socket->address, &socket->length); if (result == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); @@ -52,7 +52,7 @@ extern "C" { if (!socket) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (bind(socket->id, socket->address, socket->length) == -1) { + if (bind(socket->id, (struct sockaddr *) &socket->address, socket->length) == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EADDRINUSE) return F_status_set_error(F_busy_address); if (errno == EADDRNOTAVAIL) return F_status_set_error(F_available_not_address); @@ -80,10 +80,10 @@ extern "C" { if (socket->domain != f_socket_protocol_family_local_e) return F_status_set_error(F_local_not); - memset(socket->address, 0, sizeof(struct sockaddr_un)); + memset((void *) &socket->address, 0, sizeof(struct sockaddr_un)); { - struct sockaddr_un *address = (struct sockaddr_un *) socket->address; + struct sockaddr_un *address = (struct sockaddr_un *) &socket->address; address->sun_family = f_socket_address_family_local_e; @@ -96,7 +96,7 @@ extern "C" { } } - if (bind(socket->id, socket->address, sizeof(struct sockaddr_un)) == -1) { + if (bind(socket->id, (struct sockaddr *) &socket->address, sizeof(struct sockaddr_un)) == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EADDRINUSE) return F_status_set_error(F_busy_address); if (errno == EADDRNOTAVAIL) return F_status_set_error(F_available_not_address); @@ -119,7 +119,7 @@ extern "C" { #ifndef _di_f_socket_connect_ f_status_t f_socket_connect(const f_socket_t socket) { - if (connect(socket.id, socket.address, socket.length) == -1) { + if (connect(socket.id, (struct sockaddr *) &socket.address, socket.length) == -1) { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EADDRINUSE) return F_status_set_error(F_busy_address); if (errno == EADDRNOTAVAIL) return F_status_set_error(F_available_not_address); @@ -352,7 +352,7 @@ extern "C" { if (!socket) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (getpeername(socket->id, socket->address, &socket->length) == -1) { + if (getpeername(socket->id, (struct sockaddr *) &socket->address, &socket->length) == -1) { if (errno == EBADF) return F_status_set_error(F_file_descriptor); if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == EINVAL) return F_status_set_error(F_parameter); @@ -374,7 +374,7 @@ extern "C" { if (!buffer) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - const ssize_t result = recvfrom(socket->id, buffer, socket->size_read, flags, socket->address, &socket->length); + const ssize_t result = recvfrom(socket->id, buffer, socket->size_read, flags, (struct sockaddr *) &socket->address, &socket->length); if (result < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); @@ -491,7 +491,7 @@ extern "C" { if (!buffer) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - const ssize_t result = sendto(socket->id, buffer, socket->size_write, flags, socket->address, socket->length); + const ssize_t result = sendto(socket->id, buffer, socket->size_write, flags, (struct sockaddr *) &socket->address, socket->length); if (result < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); diff --git a/level_0/f_socket/c/socket.h b/level_0/f_socket/c/socket.h index d21cef6..f017d29 100644 --- a/level_0/f_socket/c/socket.h +++ b/level_0/f_socket/c/socket.h @@ -12,6 +12,8 @@ // Libc includes. #include +#include +#include #include #include #include @@ -19,6 +21,26 @@ #include #include +#ifdef _en_support_socket_address_at_ + #include +#endif // _en_support_socket_address_at_ + +#ifdef _en_support_socket_address_ax25_ + #include +#endif // _en_support_socket_address_ax25_ + +#ifdef _en_support_socket_address_dl_ + #include +#endif // _en_support_socket_address_dl_ + +#ifdef _en_support_socket_address_ipx_ + #include +#endif // _en_support_socket_address_ipx_ + +#ifdef _en_support_socket_address_x25_ + #include +#endif // _en_support_socket_address_x25_ + // FLL-0 includes. #include #include diff --git a/level_0/f_socket/c/socket/common.h b/level_0/f_socket/c/socket/common.h index 1eb5a87..1a8fc1c 100644 --- a/level_0/f_socket/c/socket/common.h +++ b/level_0/f_socket/c/socket/common.h @@ -85,50 +85,50 @@ extern "C" { #ifndef _di_f_socket_address_family_e_ enum { f_socket_address_family_unspecified_e = AF_UNSPEC, - f_socket_address_family_local_e = AF_LOCAL, - f_socket_address_family_inet_e = AF_INET, - f_socket_address_family_ax25_e = AF_AX25, - f_socket_address_family_ipx_e = AF_IPX, - f_socket_address_family_appletalk_e = AF_APPLETALK, - f_socket_address_family_netrom_e = AF_NETROM, - f_socket_address_family_bridge_e = AF_BRIDGE, - f_socket_address_family_atmpvc_e = AF_ATMPVC, - f_socket_address_family_x25_e = AF_X25, - f_socket_address_family_inet6_e = AF_INET6, - f_socket_address_family_rose_e = AF_ROSE, - f_socket_address_family_decnet_e = AF_DECnet, - f_socket_address_family_netbeui_e = AF_NETBEUI, - f_socket_address_family_security_e = AF_SECURITY, - f_socket_address_family_key_e = AF_KEY, - f_socket_address_family_netlink_e = AF_NETLINK, - f_socket_address_family_packet_e = AF_PACKET, - f_socket_address_family_ash_e = AF_ASH, - f_socket_address_family_econet_e = AF_ECONET, - f_socket_address_family_atmsvc_e = AF_ATMSVC, - f_socket_address_family_rds_e = AF_RDS, - f_socket_address_family_sna_e = AF_SNA, - f_socket_address_family_irda_e = AF_IRDA, - f_socket_address_family_pppox_e = AF_PPPOX, - f_socket_address_family_wanpipe_e = AF_WANPIPE, - f_socket_address_family_llc_e = AF_LLC, - f_socket_address_family_ib_e = AF_IB, - f_socket_address_family_mpls_e = AF_MPLS, - f_socket_address_family_can_e = AF_CAN, - f_socket_address_family_tipc_e = AF_TIPC, - f_socket_address_family_bluetooth_e = AF_BLUETOOTH, - f_socket_address_family_iucb_e = AF_IUCV, - f_socket_address_family_rxrpc_e = AF_RXRPC, - f_socket_address_family_isdn_e = AF_ISDN, - f_socket_address_family_phonet_e = AF_PHONET, - f_socket_address_family_ieee802154_e = AF_IEEE802154, - f_socket_address_family_caif_e = AF_CAIF, - f_socket_address_family_alg_e = AF_ALG, - f_socket_address_family_nfc_e = AF_NFC, - f_socket_address_family_vsock_e = AF_VSOCK, - f_socket_address_family_kcm_e = AF_KCM, - f_socket_address_family_qipcrtr_e = AF_QIPCRTR, - f_socket_address_family_smc_e = AF_SMC, - f_socket_address_family_max_e = AF_MAX, + f_socket_address_family_alg_e = AF_ALG, + f_socket_address_family_appletalk_e = AF_APPLETALK, + f_socket_address_family_ash_e = AF_ASH, + f_socket_address_family_atmpvc_e = AF_ATMPVC, + f_socket_address_family_atmsvc_e = AF_ATMSVC, + f_socket_address_family_ax25_e = AF_AX25, + f_socket_address_family_bluetooth_e = AF_BLUETOOTH, + f_socket_address_family_bridge_e = AF_BRIDGE, + f_socket_address_family_caif_e = AF_CAIF, + f_socket_address_family_can_e = AF_CAN, + f_socket_address_family_decnet_e = AF_DECnet, + f_socket_address_family_econet_e = AF_ECONET, + f_socket_address_family_ib_e = AF_IB, + f_socket_address_family_ieee802154_e = AF_IEEE802154, + f_socket_address_family_inet_e = AF_INET, + f_socket_address_family_inet6_e = AF_INET6, + f_socket_address_family_ipx_e = AF_IPX, + f_socket_address_family_irda_e = AF_IRDA, + f_socket_address_family_isdn_e = AF_ISDN, + f_socket_address_family_iucb_e = AF_IUCV, + f_socket_address_family_kcm_e = AF_KCM, + f_socket_address_family_key_e = AF_KEY, + f_socket_address_family_llc_e = AF_LLC, + f_socket_address_family_local_e = AF_LOCAL, + f_socket_address_family_mpls_e = AF_MPLS, + f_socket_address_family_netbeui_e = AF_NETBEUI, + f_socket_address_family_netlink_e = AF_NETLINK, + f_socket_address_family_netrom_e = AF_NETROM, + f_socket_address_family_nfc_e = AF_NFC, + f_socket_address_family_packet_e = AF_PACKET, + f_socket_address_family_phonet_e = AF_PHONET, + f_socket_address_family_pppox_e = AF_PPPOX, + f_socket_address_family_qipcrtr_e = AF_QIPCRTR, + f_socket_address_family_rds_e = AF_RDS, + f_socket_address_family_rose_e = AF_ROSE, + f_socket_address_family_rxrpc_e = AF_RXRPC, + f_socket_address_family_security_e = AF_SECURITY, + f_socket_address_family_smc_e = AF_SMC, + f_socket_address_family_sna_e = AF_SNA, + f_socket_address_family_tipc_e = AF_TIPC, + f_socket_address_family_vsock_e = AF_VSOCK, + f_socket_address_family_wanpipe_e = AF_WANPIPE, + f_socket_address_family_x25_e = AF_X25, + f_socket_address_family_max_e = AF_MAX, }; #endif // _di_f_socket_address_family_e_ @@ -151,226 +151,120 @@ extern "C" { #endif // _di_f_socket_close_e_ /** - * Socket protocol codes. + * Socket Flags. * - * Disclaimer: This may be different from system to system depending on the libc and other factors. + * These are flags to pass to either socket receive or socket send functions. * - * f_socket_protocol_*_e: - * - ip: Internet Protocol and pseudo protocol number or IPv6 Hop by Hop Option (RFC1883). - * - icmp: internet control message protocol. - * - igmp: Internet Group Management. - * - ggp: Gateway-Gateway Protocol. - * - ipencap: IP Encapsulated in IP. - * - st: ST datagram mode. - * - tcp: Transmission Control Protocol - * - egp: Exterior Gateway Protocol - * - igp: Any private Interior Gateway Protocol. - * - pup: PARC Universal Packet. - * - udp: User Datagram Protocol. - * - hmp: Host Monitoring Protocol. - * - xns_idp Xerox NS IDP. - * - rdp: Reliable Datagram Protocol. - * - iso_tp4 ISO Transport Protocol class 4 (RFC905). - * - dccp: Datagram Congestion Control Prot. (RFC4340). - * - xtp: Xpress Transfer Protocol. - * - ddp: Datagram Delivery Protocol. - * - idpr_cmtp: IDPR Control Message Transport. - * - ipv6: Internet Protocol Version 6. - * - ipv6_route Internet Protocol Version 6 Routing Header. - * - ipv6_frag Internet Protocol Version 6 Fragment Header. - * - idrp: Inter-Domain Routing Protocol. - * - rsvp: Reservation Protocol. - * - gre: General Routing Encapsulation. - * - esp: Encapsulated Security Payload (RFC2406). - * - ah: Authentication Header (RFC2402). - * - skip: SKIP. - * - ipv6_icmp ICMP for IPv6. - * - ipv6_nonxt No Next Header for IPv6. - * - ipv6_opts Destination Options for IPv6. - * - rspf: Radio Shortest Path First. - * - vmtp: Versatile Message Transport. - * - eigrp: Enhanced Interior Routing Protocol. - * - ospf: Open Shortest Path First IGP. - * - ax_25 AX.25 Frames. - * - ipip: IP within IP Encapsulation Protocol - * - etherip: Ethernet within IP Encapsulation (RFC3378). - * - encap: Yet Another IP Encapsulation (RFC1241). - * - encryption Any private encryption scheme. - * - pim: Protocol Independent Multicast. - * - ipcomp: IP Payload Compression Protocol. - * - vrrp: Virtual Router Redundancy Protocol (RFC5798). - * - l2tp: Layer Two Tunneling Protocol (RFC2661). - * - isis: IS-IS over IPv4. - * - sctp: Stream Control Transmission Protocol. - * - fc: Fibre Channel. - * - mobility_header: Mobility Support for IPv6 (RFC3775). - * - udplite: UDP-Lite (RFC3828). - * - mpls_in_ip: MPLS-in-IP (RFC4023). - * - manet: MANET Protocols (RFC5498). - * - hip: Host Identity Protocol. - * - shim6: Shim6 Protocol (RFC5533). - * - wesp: Wrapped Encapsulating Security Payload. - * - rohc: Robust Header Compression. + * f_socket_flag_*_e: + * - close_on_exit: Set the close on exit flag for a UNIX socket. + * - confirm: Inform the network layer that "forward process" happened. + * - error_queue: Designate that queue errors should be received from the socket error queue. + * - more: Designate that there is more data to send. + * - out_of_band: Enable receiving out of band data. + * - peek: Process data from the queue without popping it off the stack. + * - record_end: Designate end of record, terminating a sequence. + * - route_not: Do not use a gateway to send this packet. + * - signal_not: Do not send SIGPIPE signal if remote end closed the connection in a stream oriented connection. + * - truncate: Return real length of the packet even if it is truncated to fit into the buffer. + * - wait_all: Block until the full request is satisfied. + * - wait_not: Use non-blocking. */ -#ifndef _di_f_socket_protocol_e_ +#ifndef _di_f_socket_flag_e_ enum { - f_socket_protocol_ip = 0, - f_socket_protocol_icmp = 1, - f_socket_protocol_igmp = 2, - f_socket_protocol_ggp = 3, - f_socket_protocol_ipencap = 4, - f_socket_protocol_st = 5, - f_socket_protocol_tcp = 6, - f_socket_protocol_egp = 8, - f_socket_protocol_igp = 9, - f_socket_protocol_pup = 12, - f_socket_protocol_udp = 17, - f_socket_protocol_hmp = 20, - f_socket_protocol_xns_idp = 22, - f_socket_protocol_rdp = 27, - f_socket_protocol_iso_tp4 = 29, - f_socket_protocol_dccp = 33, - f_socket_protocol_xtp = 36, - f_socket_protocol_ddp = 37, - f_socket_protocol_idpr_cmtp = 38, - f_socket_protocol_ipv6 = 41, - f_socket_protocol_ipv6_route = 43, - f_socket_protocol_ipv6_frag = 44, - f_socket_protocol_idrp = 45, - f_socket_protocol_rsvp = 46, - f_socket_protocol_gre = 47, - f_socket_protocol_esp = 50, - f_socket_protocol_ah = 51, - f_socket_protocol_skip = 57, - f_socket_protocol_ipv6_icmp = 58, - f_socket_protocol_ipv6_nonxt = 59, - f_socket_protocol_ipv6_opts = 60, - f_socket_protocol_rspf = 73, - f_socket_protocol_vmtp = 81, - f_socket_protocol_eigrp = 88, - f_socket_protocol_ospf = 89, - f_socket_protocol_ax_25 = 93, - f_socket_protocol_ipip = 94, - f_socket_protocol_etherip = 97, - f_socket_protocol_encap = 98, - f_socket_protocol_encrypted = 99, - f_socket_protocol_pim = 103, - f_socket_protocol_ipcomp = 108, - f_socket_protocol_vrrp = 112, - f_socket_protocol_l2tp = 115, - f_socket_protocol_isis = 124, - f_socket_protocol_sctp = 132, - f_socket_protocol_fc = 133, - f_socket_protocol_mobility_header = 135, - f_socket_protocol_udplite = 136, - f_socket_protocol_mpls_in_ip = 137, - f_socket_protocol_manet = 138, - f_socket_protocol_hip = 139, - f_socket_protocol_shim6 = 140, - f_socket_protocol_wesp = 141, - f_socket_protocol_rohc = 142, + f_socket_flag_close_on_exit_e = MSG_CMSG_CLOEXEC, + f_socket_flag_confirm_e = MSG_CONFIRM, + f_socket_flag_error_queue_e = MSG_ERRQUEUE, + f_socket_flag_more_e = MSG_MORE, + f_socket_flag_out_of_band_e = MSG_OOB, + f_socket_flag_peek_e = MSG_PEEK, + f_socket_flag_record_end_e = MSG_EOR, + f_socket_flag_route_not_e = MSG_DONTROUTE, + f_socket_flag_signal_not_e = MSG_NOSIGNAL, + f_socket_flag_truncate_e = MSG_TRUNC, + f_socket_flag_wait_all_e = MSG_WAITALL, + f_socket_flag_wait_not_e = MSG_DONTWAIT, }; -#endif // _di_f_socket_protocol_e_ +#endif // _di_f_socket_flag_e_ /** - * Socket protocol families, referred to as a domain. + * Socket levels. * - * f_socket_protocol_family_*_e: - * - unspecified: No protocol family specified. - * - local: Localhost, pipes, Unix sockets, or file sockets (PF_LOCAL, PF_UNIX, PF_FILE). - * - inet: IP protocol family. - * - ax25: Amateur Radio AX.25. - * - ipx: Novell Internet Protocol. - * - appletalk: Appletalk DDP. - * - netrom: Amateur radio NetROM. - * - bridge: Multiprotocol bridge. - * - atmpvc: ATM PVCs. - * - x25: Reserved for X.25 project. - * - inet6: IP version 6. - * - rose: Amateur Radio X.25 PLP. - * - decnet: Reserved for DECnet project. - * - netbeui: Reserved for 802.2LLC project. - * - security: Security callback pseudo AF. - * - key: PF_KEY key management API. - * - netlink: Netlink and BSD (PF_NETLINK and PF_ROUTE). - * - packet: Packet family. - * - ash: Ash. - * - econet: Acorn Econet. - * - atmsvc: ATM SVCs. - * - rds: RDS sockets. - * - sna: Linux SNA Project. - * - irda: IRDA sockets. - * - pppox: PPPoX sockets. - * - wanpipe: Wanpipe API sockets. - * - llc: Linux LLC. - * - ib: Native InfiniBand address. - * - mpls: MPLS. - * - can: Controller Area Network. - * - tipc: TIPC sockets. - * - bluetooth: Bluetooth sockets. - * - iucb: IUCV sockets. - * - rxrpc: RxRPC sockets. - * - isdn: mISDN sockets. - * - phonet: Phonet sockets. - * - ieee802154: IEEE 802.15.4 sockets. - * - caif: CAIF sockets. - * - alg: Algorithm sockets. - * - nfc: NFC sockets. - * - vsock: vSockets. - * - kcm: Kernel Connection Multiplexor. - * - qipcrtr: Qualcomm IPC Router. - * - smc: SMC sockets. - * - max: The maximum value for known protocol families (this is not a protocol family). + * These are from the SOL_* macros. + * + * f_socket_level_*_e: + * - aal: ATM Adaption Layer (packet level). + * - alg: Alg. + * - atm: ATM layer (cell level). + * - bluetooth: Bluetooth. + * - caif: Caif. + * - dccp: Dccp. + * - decnet: Decnet. + * - irda: Irda. + * - iucv: Iucv. + * - kcm: Kcm. + * - llc: Llc. + * - netbeui: Netbeui. + * - netlink: Netlink. + * - nfc: Nfc. + * - packet: Packet. + * - pnpipe: Pnpipe. + * - ppol2tp: Ppol2tp. + * - raw: Raw. + * - rds: Rds. + * - rxrpc: Rxrpc. + * - tipc: Tipc. + * - tls: Tls. + * - x25: X25. */ -#ifndef _di_f_socket_protocol_family_e_ +#ifndef _di_f_socket_level_e_ enum { - f_socket_protocol_family_unspecified_e = PF_UNSPEC, - f_socket_protocol_family_local_e = PF_LOCAL, - f_socket_protocol_family_inet_e = PF_INET, - f_socket_protocol_family_ax25_e = PF_AX25, - f_socket_protocol_family_ipx_e = PF_IPX, - f_socket_protocol_family_appletalk_e = PF_APPLETALK, - f_socket_protocol_family_netrom_e = PF_NETROM, - f_socket_protocol_family_bridge_e = PF_BRIDGE, - f_socket_protocol_family_atmpvc_e = PF_ATMPVC, - f_socket_protocol_family_x25_e = PF_X25, - f_socket_protocol_family_inet6_e = PF_INET6, - f_socket_protocol_family_rose_e = PF_ROSE, - f_socket_protocol_family_decnet_e = PF_DECnet, - f_socket_protocol_family_netbeui_e = PF_NETBEUI, - f_socket_protocol_family_security_e = PF_SECURITY, - f_socket_protocol_family_key_e = PF_KEY, - f_socket_protocol_family_netlink_e = PF_NETLINK, - f_socket_protocol_family_packet_e = PF_PACKET, - f_socket_protocol_family_ash_e = PF_ASH, - f_socket_protocol_family_econet_e = PF_ECONET, - f_socket_protocol_family_atmsvc_e = PF_ATMSVC, - f_socket_protocol_family_rds_e = PF_RDS, - f_socket_protocol_family_sna_e = PF_SNA, - f_socket_protocol_family_irda_e = PF_IRDA, - f_socket_protocol_family_pppox_e = PF_PPPOX, - f_socket_protocol_family_wanpipe_e = PF_WANPIPE, - f_socket_protocol_family_llc_e = PF_LLC, - f_socket_protocol_family_ib_e = PF_IB, - f_socket_protocol_family_mpls_e = PF_MPLS, - f_socket_protocol_family_can_e = PF_CAN, - f_socket_protocol_family_tipc_e = PF_TIPC, - f_socket_protocol_family_bluetooth_e = PF_BLUETOOTH, - f_socket_protocol_family_iucb_e = PF_IUCV, - f_socket_protocol_family_rxrpc_e = PF_RXRPC, - f_socket_protocol_family_isdn_e = PF_ISDN, - f_socket_protocol_family_phonet_e = PF_PHONET, - f_socket_protocol_family_ieee802154_e = PF_IEEE802154, - f_socket_protocol_family_caif_e = PF_CAIF, - f_socket_protocol_family_alg_e = PF_ALG, - f_socket_protocol_family_nfc_e = PF_NFC, - f_socket_protocol_family_vsock_e = PF_VSOCK, - f_socket_protocol_family_kcm_e = PF_KCM, - f_socket_protocol_family_qipcrtr_e = PF_QIPCRTR, - f_socket_protocol_family_smc_e = PF_SMC, - f_socket_protocol_family_max_e = PF_MAX, + f_socket_level_aal_e = SOL_AAL, + f_socket_level_alg_e = SOL_ALG, + f_socket_level_atm_e = SOL_ATM, + f_socket_level_bluetooth_e = SOL_BLUETOOTH, + f_socket_level_caif_e = SOL_CAIF, + f_socket_level_dccp_e = SOL_DCCP, + f_socket_level_decnet_e = SOL_DECNET, + f_socket_level_irda_e = SOL_IRDA, + f_socket_level_iucv_e = SOL_IUCV, + f_socket_level_kcm_e = SOL_KCM, + f_socket_level_llc_e = SOL_LLC, + f_socket_level_netbeui_e = SOL_NETBEUI, + f_socket_level_netlink_e = SOL_NETLINK, + f_socket_level_nfc_e = SOL_NFC, + f_socket_level_packet_e = SOL_PACKET, + f_socket_level_pnpipe_e = SOL_PNPIPE, + f_socket_level_ppol2tp_e = SOL_PPPOL2TP, + f_socket_level_raw_e = SOL_RAW, + f_socket_level_rds_e = SOL_RDS, + f_socket_level_rxrpc_e = SOL_RXRPC, + f_socket_level_tipc_e = SOL_TIPC, + f_socket_level_tls_e = SOL_TLS, + f_socket_level_x25_e = SOL_X25, }; -#endif // _di_f_socket_protocol_family_e_ +#endif // _di_f_socket_level_e_ + +/** + * Socket Message Flags. + * + * These represent responses from socket messages (see recvmsg()). + * + * f_socket_message_flag_*_e: + * - error_queue: No data received but extended error from the socket error queue is received. + * - out_of_band: The message is expedited or out of band data is received. + * - record_end: End of record reached. + * - truncate: The data has been truncated due to lack of space in the buffer. + * - truncate_control: The control data has been truncated due to lack of space in the buffer. + */ +#ifndef _di_f_socket_message_flag_e_ + enum { + f_socket_message_flag_error_queue_e = MSG_ERRQUEUE, + f_socket_message_flag_out_of_band_e = MSG_OOB, + f_socket_message_flag_record_end_e = MSG_EOR, + f_socket_message_flag_truncate_e = MSG_TRUNC, + f_socket_message_flag_truncate_control_e = MSG_CTRUNC, + }; +#endif // _di_f_socket_message_flag_e_ /** * Socket Options. @@ -509,62 +403,226 @@ extern "C" { #endif // _di_f_socket_option_e_ /** - * Socket Flags. + * Socket protocol codes. * - * These are flags to pass to either socket receive or socket send functions. + * Disclaimer: This may be different from system to system depending on the libc and other factors. * - * f_socket_flag_*_e: - * - close_on_exit: Set the close on exit flag for a UNIX socket. - * - confirm: Inform the network layer that "forward process" happened. - * - error_queue: Designate that queue errors should be received from the socket error queue. - * - more: Designate that there is more data to send. - * - out_of_band: Enable receiving out of band data. - * - peek: Process data from the queue without popping it off the stack. - * - record_end: Designate end of record, terminating a sequence. - * - route_not: Do not use a gateway to send this packet. - * - signal_not: Do not send SIGPIPE signal if remote end closed the connection in a stream oriented connection. - * - truncate: Return real length of the packet even if it is truncated to fit into the buffer. - * - wait_all: Block until the full request is satisfied. - * - wait_not: Use non-blocking. + * f_socket_protocol_*_e: + * - ip: Internet Protocol and pseudo protocol number or IPv6 Hop by Hop Option (RFC1883). + * - ah: Authentication Header (RFC2402). + * - ax25: AX.25 Frames. + * - dccp: Datagram Congestion Control Prot. (RFC4340). + * - ddp: Datagram Delivery Protocol. + * - egp: Exterior Gateway Protocol + * - eigrp: Enhanced Interior Routing Protocol. + * - encap: Yet Another IP Encapsulation (RFC1241). + * - encryption: Any private encryption scheme. + * - esp: Encapsulated Security Payload (RFC2406). + * - etherip: Ethernet within IP Encapsulation (RFC3378). + * - fc: Fibre Channel. + * - ggp: Gateway-Gateway Protocol. + * - gre: General Routing Encapsulation. + * - hip: Host Identity Protocol. + * - hmp: Host Monitoring Protocol. + * - icmp: internet control message protocol. + * - idpr_cmtp: IDPR Control Message Transport. + * - idrp: Inter-Domain Routing Protocol. + * - igmp: Internet Group Management. + * - igp: Any private Interior Gateway Protocol. + * - ipcomp: IP Payload Compression Protocol. + * - ipencap: IP Encapsulated in IP. + * - ipip: IP within IP Encapsulation Protocol + * - ipv6: Internet Protocol Version 6. + * - ipv6_frag: Internet Protocol Version 6 Fragment Header. + * - ipv6_icmp: ICMP for IPv6. + * - ipv6_nonxt: No Next Header for IPv6. + * - ipv6_opts: Destination Options for IPv6. + * - ipv6_route: Internet Protocol Version 6 Routing Header. + * - isis: IS-IS over IPv4. + * - iso_tp4: ISO Transport Protocol class 4 (RFC905). + * - l2tp: Layer Two Tunneling Protocol (RFC2661). + * - manet: MANET Protocols (RFC5498). + * - mobility_header: Mobility Support for IPv6 (RFC3775). + * - mpls_in_ip: MPLS-in-IP (RFC4023). + * - ospf: Open Shortest Path First IGP. + * - pim: Protocol Independent Multicast. + * - pup: PARC Universal Packet. + * - rdp: Reliable Datagram Protocol. + * - rohc: Robust Header Compression. + * - rspf: Radio Shortest Path First. + * - rsvp: Reservation Protocol. + * - sctp: Stream Control Transmission Protocol. + * - shim6: Shim6 Protocol (RFC5533). + * - skip: SKIP. + * - st: ST datagram mode. + * - tcp: Transmission Control Protocol + * - udp: User Datagram Protocol. + * - udplite: UDP-Lite (RFC3828). + * - vmtp: Versatile Message Transport. + * - vrrp: Virtual Router Redundancy Protocol (RFC5798). + * - wesp: Wrapped Encapsulating Security Payload. + * - xns_idp: Xerox NS IDP. + * - xtp: Xpress Transfer Protocol. */ -#ifndef _di_f_socket_flag_e_ +#ifndef _di_f_socket_protocol_e_ enum { - f_socket_flag_close_on_exit_e = MSG_CMSG_CLOEXEC, - f_socket_flag_confirm_e = MSG_CONFIRM, - f_socket_flag_error_queue_e = MSG_ERRQUEUE, - f_socket_flag_more_e = MSG_MORE, - f_socket_flag_out_of_band_e = MSG_OOB, - f_socket_flag_peek_e = MSG_PEEK, - f_socket_flag_record_end_e = MSG_EOR, - f_socket_flag_route_not_e = MSG_DONTROUTE, - f_socket_flag_signal_not_e = MSG_NOSIGNAL, - f_socket_flag_truncate_e = MSG_TRUNC, - f_socket_flag_wait_all_e = MSG_WAITALL, - f_socket_flag_wait_not_e = MSG_DONTWAIT, + f_socket_protocol_ip = 0, + f_socket_protocol_ah = 51, + f_socket_protocol_ax25 = 93, + f_socket_protocol_dccp = 33, + f_socket_protocol_ddp = 37, + f_socket_protocol_egp = 8, + f_socket_protocol_eigrp = 88, + f_socket_protocol_encap = 98, + f_socket_protocol_encryption = 99, + f_socket_protocol_esp = 50, + f_socket_protocol_etherip = 97, + f_socket_protocol_fc = 133, + f_socket_protocol_ggp = 3, + f_socket_protocol_gre = 47, + f_socket_protocol_hip = 139, + f_socket_protocol_hmp = 20, + f_socket_protocol_icmp = 1, + f_socket_protocol_idpr_cmtp = 38, + f_socket_protocol_idrp = 45, + f_socket_protocol_igmp = 2, + f_socket_protocol_igp = 9, + f_socket_protocol_ipcomp = 108, + f_socket_protocol_ipencap = 4, + f_socket_protocol_ipip = 94, + f_socket_protocol_ipv6 = 41, + f_socket_protocol_ipv6_frag = 44, + f_socket_protocol_ipv6_icmp = 58, + f_socket_protocol_ipv6_nonxt = 59, + f_socket_protocol_ipv6_opts = 60, + f_socket_protocol_ipv6_route = 43, + f_socket_protocol_isis = 124, + f_socket_protocol_iso_tp4 = 29, + f_socket_protocol_l2tp = 115, + f_socket_protocol_manet = 138, + f_socket_protocol_mobility_header = 135, + f_socket_protocol_mpls_in_ip = 137, + f_socket_protocol_ospf = 89, + f_socket_protocol_pim = 103, + f_socket_protocol_pup = 12, + f_socket_protocol_rdp = 27, + f_socket_protocol_rohc = 142, + f_socket_protocol_rspf = 73, + f_socket_protocol_rsvp = 46, + f_socket_protocol_sctp = 132, + f_socket_protocol_shim6 = 140, + f_socket_protocol_skip = 57, + f_socket_protocol_st = 5, + f_socket_protocol_tcp = 6, + f_socket_protocol_udp = 17, + f_socket_protocol_udplite = 136, + f_socket_protocol_vmtp = 81, + f_socket_protocol_vrrp = 112, + f_socket_protocol_wesp = 141, + f_socket_protocol_xns_idp = 22, + f_socket_protocol_xtp = 36, }; -#endif // _di_f_socket_flag_e_ +#endif // _di_f_socket_protocol_e_ /** - * Socket Message Flags. - * - * These represent responses from socket messages (see recvmsg()). + * Socket protocol families, referred to as a domain. * - * f_socket_message_flag_*_e: - * - error_queue: No data received but extended error from the socket error queue is received. - * - out_of_band: The message is expedited or out of band data is received. - * - record_end: End of record reached. - * - truncate: The data has been truncated due to lack of space in the buffer. - * - truncate_control: The control data has been truncated due to lack of space in the buffer. + * f_socket_protocol_family_*_e: + * - unspecified: No protocol family specified. + * - local: Localhost, pipes, Unix sockets, or file sockets (PF_LOCAL, PF_UNIX, PF_FILE). + * - inet: IP protocol family. + * - ax25: Amateur Radio AX.25. + * - ipx: Novell Internet Protocol. + * - appletalk: Appletalk DDP. + * - netrom: Amateur radio NetROM. + * - bridge: Multiprotocol bridge. + * - atmpvc: ATM PVCs. + * - x25: Reserved for X.25 project. + * - inet6: IP version 6. + * - rose: Amateur Radio X.25 PLP. + * - decnet: Reserved for DECnet project. + * - netbeui: Reserved for 802.2LLC project. + * - security: Security callback pseudo AF. + * - key: PF_KEY key management API. + * - netlink: Netlink and BSD (PF_NETLINK and PF_ROUTE). + * - packet: Packet family. + * - ash: Ash. + * - econet: Acorn Econet. + * - atmsvc: ATM SVCs. + * - rds: RDS sockets. + * - sna: Linux SNA Project. + * - irda: IRDA sockets. + * - pppox: PPPoX sockets. + * - wanpipe: Wanpipe API sockets. + * - llc: Linux LLC. + * - ib: Native InfiniBand address. + * - mpls: MPLS. + * - can: Controller Area Network. + * - tipc: TIPC sockets. + * - bluetooth: Bluetooth sockets. + * - iucb: IUCV sockets. + * - rxrpc: RxRPC sockets. + * - isdn: mISDN sockets. + * - phonet: Phonet sockets. + * - ieee802154: IEEE 802.15.4 sockets. + * - caif: CAIF sockets. + * - alg: Algorithm sockets. + * - nfc: NFC sockets. + * - vsock: vSockets. + * - kcm: Kernel Connection Multiplexor. + * - qipcrtr: Qualcomm IPC Router. + * - smc: SMC sockets. + * - max: The maximum value for known protocol families (this is not a protocol family). */ -#ifndef _di_f_socket_message_flag_e_ +#ifndef _di_f_socket_protocol_family_e_ enum { - f_socket_message_flag_error_queue_e = MSG_ERRQUEUE, - f_socket_message_flag_out_of_band_e = MSG_OOB, - f_socket_message_flag_record_end_e = MSG_EOR, - f_socket_message_flag_truncate_e = MSG_TRUNC, - f_socket_message_flag_truncate_control_e = MSG_CTRUNC, + f_socket_protocol_family_unspecified_e = PF_UNSPEC, + f_socket_protocol_family_alg_e = PF_ALG, + f_socket_protocol_family_appletalk_e = PF_APPLETALK, + f_socket_protocol_family_ash_e = PF_ASH, + f_socket_protocol_family_atmpvc_e = PF_ATMPVC, + f_socket_protocol_family_atmsvc_e = PF_ATMSVC, + f_socket_protocol_family_ax25_e = PF_AX25, + f_socket_protocol_family_bluetooth_e = PF_BLUETOOTH, + f_socket_protocol_family_bridge_e = PF_BRIDGE, + f_socket_protocol_family_caif_e = PF_CAIF, + f_socket_protocol_family_can_e = PF_CAN, + f_socket_protocol_family_decnet_e = PF_DECnet, + f_socket_protocol_family_econet_e = PF_ECONET, + f_socket_protocol_family_ib_e = PF_IB, + f_socket_protocol_family_ieee802154_e = PF_IEEE802154, + f_socket_protocol_family_inet_e = PF_INET, + f_socket_protocol_family_inet6_e = PF_INET6, + f_socket_protocol_family_ipx_e = PF_IPX, + f_socket_protocol_family_irda_e = PF_IRDA, + f_socket_protocol_family_isdn_e = PF_ISDN, + f_socket_protocol_family_iucb_e = PF_IUCV, + f_socket_protocol_family_kcm_e = PF_KCM, + f_socket_protocol_family_key_e = PF_KEY, + f_socket_protocol_family_llc_e = PF_LLC, + f_socket_protocol_family_local_e = PF_LOCAL, + f_socket_protocol_family_mpls_e = PF_MPLS, + f_socket_protocol_family_netbeui_e = PF_NETBEUI, + f_socket_protocol_family_netlink_e = PF_NETLINK, + f_socket_protocol_family_netrom_e = PF_NETROM, + f_socket_protocol_family_nfc_e = PF_NFC, + f_socket_protocol_family_packet_e = PF_PACKET, + f_socket_protocol_family_phonet_e = PF_PHONET, + f_socket_protocol_family_pppox_e = PF_PPPOX, + f_socket_protocol_family_qipcrtr_e = PF_QIPCRTR, + f_socket_protocol_family_rds_e = PF_RDS, + f_socket_protocol_family_rose_e = PF_ROSE, + f_socket_protocol_family_rxrpc_e = PF_RXRPC, + f_socket_protocol_family_security_e = PF_SECURITY, + f_socket_protocol_family_smc_e = PF_SMC, + f_socket_protocol_family_sna_e = PF_SNA, + f_socket_protocol_family_tipc_e = PF_TIPC, + f_socket_protocol_family_vsock_e = PF_VSOCK, + f_socket_protocol_family_wanpipe_e = PF_WANPIPE, + f_socket_protocol_family_x25_e = PF_X25, + f_socket_protocol_family_max_e = PF_MAX, }; -#endif // _di_f_socket_message_flag_e_ +#endif // _di_f_socket_protocol_family_e_ /** * Socket types. @@ -591,6 +649,88 @@ extern "C" { #endif // _di_f_socket_type_e_ /** + * Provide a union to simplify using struct sockaddr in arrays. + * + * Managing different structures is not as practical. + * At the cost of resources, use the same space for all of these. + * This can then easily be used in a generic array that has a mixture of these. + * + * All of the properties may or may not be present, but inet4, inet6, and local are generally assumed to exist. + * + * Properties: + * - arp: Arp. + * - at: At. + * - ax25: Ax25. + * - dl: Dl. + * - eon: Eon. + * - inet4: Ipv4 internet network socket. + * - inet6: Ipv6 internet network socket.. + * - ipx: Ipx. + * - iso: Iso. + * - local: Local (aka: Unix) socket (socket file or localhost). + * - ns: Ns. + * - x25: X25. + */ +#ifndef _di_f_socket_address_t_ + typedef union { + struct sockaddr_in inet4; + struct sockaddr_in6 inet6; + struct sockaddr_un local; + + #ifdef _en_support_socket_address_arp_ + struct sockaddr_inarp arp; + #endif // _en_support_socket_address_arp_ + + #ifdef _en_support_socket_address_at_ + struct sockaddr_at at; + #endif // _en_support_socket_address_at_ + + #ifdef _en_support_socket_address_ax25_ + struct sockaddr_ax25 ax25; + #endif // _en_support_socket_address_ax25_ + + #ifdef _en_support_socket_address_dl_ + struct sockaddr_dl dl; + #endif // _en_support_socket_address_dl_ + + #ifdef _en_support_socket_address_eon_ + struct sockaddr_eon eon; + #endif // _en_support_socket_address_eon_ + + #ifdef _en_support_socket_address_ipx_ + struct sockaddr_ipx ipx; + #endif // _en_support_socket_address_ipx_ + + #ifdef _en_support_socket_address_iso_ + struct sockaddr_iso iso; + #endif // _en_support_socket_address_iso_ + + #ifdef _en_support_socket_address_ns_ + struct sockaddr_ns ns; + #endif // _en_support_socket_address_ns_ + + #ifdef _en_support_socket_address_x25_ + struct sockaddr_x25 x25; + #endif // _en_support_socket_address_x25_ + } f_socket_address_t; + + #define f_socket_address_t_initialize { 0 } + + #define f_socket_address_initialize_inet4(value_inet4) { .inet4 = value_inet4 } + #define f_socket_address_initialize_inet6(value_inet6) { .inet6 = value_inet6 } + #define f_socket_address_initialize_local(value_local) { .local = value_local } + #define f_socket_address_initialize_arp(value_arp) { .arp = value_arp } + #define f_socket_address_initialize_at(value_at) { .at = value_at } + #define f_socket_address_initialize_ax25(value_ax25) { .ax25 = value_ax25 } + #define f_socket_address_initialize_dl(value_dl) { .dl = value_dl } + #define f_socket_address_initialize_eon(value_eon) { .local = value_eon } + #define f_socket_address_initialize_ipx(value_ipx) { .ipx = value_ipx } + #define f_socket_address_initialize_iso(value_iso) { .iso = value_iso } + #define f_socket_address_initialize_ns(value_ns) { .ns = value_ns } + #define f_socket_address_initialize_x25(value_x25) { .x25 = value_x25 } +#endif // _di_f_socket_address_t_ + +/** * Commonly used socket related properties, loosely based off of f_file_t. * * id: File descriptor, with a value of -1 represents a closed file. @@ -602,9 +742,11 @@ extern "C" { * size_write: The default number of 1-byte characters to read at a time and is often used for the write buffer size. * * length: The length of the socket. - * address: Pointer to the socket address (stored as "struct sockaddr" but may represent other types such as "struct sockaddr_un" or "struct sockaddr_in"). + * address: Tthe socket address. * * name: The name of the socket, if a name is given (for UNIX sockets this represents the path) (Must be a NULL terminated string). + * + * The clear and reset macros do not clear or reset the address (type f_socket_address_t) because the struct sockaddr is defined outside of the FLL project. */ #ifndef _di_f_socket_t_ typedef struct { @@ -617,12 +759,12 @@ extern "C" { size_t size_write; socklen_t length; - struct sockaddr *address; + f_socket_address_t address; f_string_static_t name; } f_socket_t; - #define f_socket_t_initialize { -1, 0, 0, 0, F_socket_default_read_size_d, F_socket_default_write_size_d, 0, 0, f_string_empty_s } + #define f_socket_t_initialize { -1, 0, 0, 0, F_socket_default_read_size_d, F_socket_default_write_size_d, 0, f_socket_address_t_initialize, f_string_empty_s } #define macro_f_socket_t_initialize_1(address, length) { \ -1, \ @@ -680,7 +822,6 @@ extern "C" { file.size_read = 0; \ file.size_write = 0; \ file.length = 0; \ - file.address = 0; \ macro_f_string_static_t_clear(file); #define macro_f_socket_t_reset(file) \ @@ -691,7 +832,6 @@ extern "C" { file.size_read = F_socket_default_read_size_d; \ file.size_write = F_socket_default_write_size_d; \ file.length = 0; \ - file.address = 0; \ macro_f_string_static_t_clear(file); #endif // _di_f_socket_t_ diff --git a/level_0/f_socket/data/build/defines b/level_0/f_socket/data/build/defines index c665317..b1f9a13 100644 --- a/level_0/f_socket/data/build/defines +++ b/level_0/f_socket/data/build/defines @@ -1,2 +1,11 @@ # fss-0000 +_en_support_socket_address_arp_ Enables support for the arp socket structure within the f_socket_address_t union. +_en_support_socket_address_at_ Enables support for the at socket structure within the f_socket_address_t union. +_en_support_socket_address_ax25_ Enables support for the ax25 socket structure within the f_socket_address_t union. +_en_support_socket_address_dl_ Enables support for the dl socket structure within the f_socket_address_t union. +_en_support_socket_address_eon_ Enables support for the eon socket structure within the f_socket_address_t union. +_en_support_socket_address_ipx_ Enables support for the ipx socket structure within the f_socket_address_t union. +_en_support_socket_address_iso_ Enables support for the iso socket structure within the f_socket_address_t union. +_en_support_socket_address_ns_ Enables support for the ns socket structure within the f_socket_address_t union. +_en_support_socket_address_x25_ Enables support for the x25 socket structure within the f_socket_address_t union.