From 26f4afb088ad0f9dfea114704b6d9015c67ad953 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 5 Jul 2023 20:37:53 -0500 Subject: [PATCH] Update: Socket file settings, use enumerations rather than defines, and add family enumerations. This expands the socket family and makes their use more correct and consistent with existing ones. The socket domain is renamed where possible to be protocol family or address family. Bring in a lot of the existing family type codes (both protocol family and address family). --- build/stand_alone/fake.config.h | 8 +- level_0/f_socket/c/socket.c | 4 +- level_0/f_socket/c/socket.h | 7 +- level_0/f_socket/c/socket/common.h | 548 ++++++++++++++++----- .../f_socket/tests/unit/c/test-socket-bind_local.c | 10 +- level_3/control/c/control.c | 2 +- level_3/control/c/private-control.c | 4 +- level_3/controller/c/controller.c | 2 +- 8 files changed, 446 insertions(+), 139 deletions(-) diff --git a/build/stand_alone/fake.config.h b/build/stand_alone/fake.config.h index 93d0da3..cec4e68 100644 --- a/build/stand_alone/fake.config.h +++ b/build/stand_alone/fake.config.h @@ -1488,6 +1488,7 @@ #define _di_f_signal_wait_until_ #define _di_f_socket_accept_ +#define _di_f_socket_address_family_e_ #define _di_f_socket_bind_ #define _di_f_socket_bind_local_ #define _di_f_socket_close_e_ @@ -1496,16 +1497,17 @@ #define _di_f_socket_create_pair_ #define _di_f_socket_default_d_ #define _di_f_socket_disconnect_ -#define _di_f_socket_domain_d_ -#define _di_f_socket_flag_d_ +#define _di_f_socket_flag_e_ #define _di_f_socket_host_name_ #define _di_f_socket_listen_ -#define _di_f_socket_message_flag_d_ +#define _di_f_socket_message_flag_e_ #define _di_f_socket_name_host_ #define _di_f_socket_name_peer_ #define _di_f_socket_option_d_ #define _di_f_socket_option_get_ #define _di_f_socket_option_set_ +#define _di_f_socket_protocol_e_ +#define _di_f_socket_protocol_family_e_ #define _di_f_socket_read_ #define _di_f_socket_read_message_ #define _di_f_socket_read_stream_ diff --git a/level_0/f_socket/c/socket.c b/level_0/f_socket/c/socket.c index 4bd4ae0..54973d9 100644 --- a/level_0/f_socket/c/socket.c +++ b/level_0/f_socket/c/socket.c @@ -78,14 +78,14 @@ extern "C" { if (!socket) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (socket->domain != f_socket_domain_file_d) return F_status_set_error(F_local_not); + 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)); { struct sockaddr_un *address = (struct sockaddr_un *) socket->address; - address->sun_family = f_socket_domain_file_d; + address->sun_family = f_socket_address_family_local_e; if (socket->name.used && socket->name.string) { strncpy(address->sun_path, socket->name.string, socket->name.used); diff --git a/level_0/f_socket/c/socket.h b/level_0/f_socket/c/socket.h index 6f7fe36..d21cef6 100644 --- a/level_0/f_socket/c/socket.h +++ b/level_0/f_socket/c/socket.h @@ -121,8 +121,9 @@ extern "C" { * @param socket * The socket structure. * The socket.address must point to a "struct sockaddr_un". + * The socket.domain (potocol family) must be assigned to f_socket_protocol_family_local_e. + * The socket.type (address family) will be assigned to f_socket_address_family_local_e. * The socket.name must be assigned to a path. - * The socket.type must be assigned to f_socket_domain_file_d. * * @return * F_none on success. @@ -191,9 +192,9 @@ extern "C" { * @param socket * The socket structure. * The socket.address may point to any valid structure, like "struct sockaddr", "struct sockaddr_un", or "struct sockaddr_in". - * The socket.domain must be assigned the desired domain. - * The socket.type must be assigned the desired type. + * The socket.domain must be assigned the desired domain (protocol family). * The socket.protocol must be assigned the desired protocol. + * The socket.type must be assigned the desired type (address family). * The socket.id will be updated with a file descriptor representing the created socket. * * @return diff --git a/level_0/f_socket/c/socket/common.h b/level_0/f_socket/c/socket/common.h index b03ea69..1eb5a87 100644 --- a/level_0/f_socket/c/socket/common.h +++ b/level_0/f_socket/c/socket/common.h @@ -31,6 +31,108 @@ extern "C" { #endif // _di_f_socket_default_d_ /** + * Socket address families. + * + * Many libc implementations have the AF_* directly map to PF_*. + * + * f_socket_address_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_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, + }; +#endif // _di_f_socket_address_family_e_ + +/** * Socket Closes. * * f_socket_close_*: @@ -49,32 +151,226 @@ extern "C" { #endif // _di_f_socket_close_e_ /** + * Socket protocol codes. + * + * Disclaimer: This may be different from system to system depending on the libc and other factors. + * + * 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. + */ +#ifndef _di_f_socket_protocol_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, + }; +#endif // _di_f_socket_protocol_e_ + +/** * Socket protocol families, referred to as a domain. * - * f_socket_domain_*: - * - atm: Raw ATM PVC. - * - apple_talk: Apple Talk. - * - cryptographic: Kernel cryptographic API. - * - file: Unix/Local file. - * - ipv4: Internet Protocol v4. - * - ipv6: Internet Protocol v6. - * - ipx: Novell IPX. - * - kernel: Kernel user interface device. - * - radio: Amateur Radio. - * - x25: ITU-T X.25 / ISO-8208 protocol + * 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_domain_d_ - #define f_socket_domain_apple_talk_d AF_APPLETALK - #define f_socket_domain_atm_d AF_ATMPVC - #define f_socket_domain_cryptographic_d AF_ALG - #define f_socket_domain_file_d AF_UNIX - #define f_socket_domain_ipv4_d AF_INET - #define f_socket_domain_ipv6_d AF_INET6 - #define f_socket_domain_ipx_d AF_IPX - #define f_socket_domain_kernel_d AF_NETLINK - #define f_socket_domain_radio_d AF_AX25 - #define f_socket_domain_x25_d AF_X25 -#endif // _di_f_socket_domain_d_ +#ifndef _di_f_socket_protocol_family_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, + }; +#endif // _di_f_socket_protocol_family_e_ /** * Socket Options. @@ -144,78 +440,80 @@ extern "C" { * - wifi_status: Wifi status. * - zero_copy_d Zero copy. */ -#ifndef _di_f_socket_option_d_ - #define f_socket_option_address_reuse_d SO_REUSEADDR - #define f_socket_option_advice_cnx_d SO_CNX_ADVICE - #define f_socket_option_bpf_attach_d SO_ATTACH_BPF - #define f_socket_option_bpf_detach_d SO_DETACH_BPF - #define f_socket_option_bpf_extensions_d SO_BPF_EXTENSIONS - #define f_socket_option_broadcast_d SO_BROADCAST - #define f_socket_option_buffer_receive_d SO_RCVBUF - #define f_socket_option_buffer_receive_force_d SO_RCVBUFFORCE - #define f_socket_option_buffer_send_d SO_SNDBUF - #define f_socket_option_buffer_send_force_d SO_SNDBUFFORCE - #define f_socket_option_cbpf_port_reuse_attach_d SO_ATTACH_REUSEPORT_CBPF - #define f_socket_option_check_not_d SO_NO_CHECK - #define f_socket_option_compatibility_bsd_d SO_BSDCOMPAT - #define f_socket_option_connection_accept_d SO_ACCEPTCONN - #define f_socket_option_cookie_d SO_COOKIE - #define f_socket_option_cpu_incoming_d SO_INCOMING_CPU - #define f_socket_option_credentials_pass_d SO_PASSCRED - #define f_socket_option_credentials_peer_d SO_PEERCRED - #define f_socket_option_debug_d SO_DEBUG - #define f_socket_option_device_bind_d SO_BINDTODEVICE - #define f_socket_option_domain_d SO_DOMAIN - #define f_socket_option_ebpf_port_reuse_attach_d SO_ATTACH_REUSEPORT_EBPF - #define f_socket_option_error_d SO_ERROR - #define f_socket_option_filter_attach_d SO_ATTACH_FILTER - #define f_socket_option_filter_detach_d SO_DETACH_FILTER - #define f_socket_option_filter_get_d SO_GET_FILTER - #define f_socket_option_filter_lock_d SO_LOCK_FILTER - #define f_socket_option_frame_check_sequence_not_d SO_NOFCS - #define f_socket_option_groups_peer_d SO_PEERGROUPS - #define f_socket_option_keep_alive_d SO_KEEPALIVE - #define f_socket_option_linger_d SO_LINGER - #define f_socket_option_low_at_receive_d SO_RCVLOWAT - #define f_socket_option_low_at_send_d SO_SNDLOWAT - #define f_socket_option_mark_d SO_MARK - #define f_socket_option_memory_information_d SO_MEMINFO - #define f_socket_option_name_peer_d SO_PEERNAME - #define f_socket_option_napi_id_incoming_d SO_INCOMING_NAPI_ID - #define f_socket_option_out_of_band_inline_d SO_OOBINLINE - #define f_socket_option_pacing_rate_max_d SO_MAX_PACING_RATE - #define f_socket_option_peek_off_d SO_PEEK_OFF - #define f_socket_option_poll_busy_d SO_BUSY_POLL - #define f_socket_option_port_reuse_d SO_REUSEPORT - #define f_socket_option_priority_d SO_PRIORITY - #define f_socket_option_protocol_d SO_PROTOCOL - #define f_socket_option_receive_overflow_d SO_RXQ_OVFL - #define f_socket_option_route_not_d SO_DONTROUTE - #define f_socket_option_security_authentication_d SO_SECURITY_AUTHENTICATION - #define f_socket_option_security_network_d SO_SECURITY_ENCRYPTION_NETWORK - #define f_socket_option_security_pass_d SO_PASSSEC - #define f_socket_option_security_peer_d SO_PEERSEC - #define f_socket_option_security_transport_d SO_SECURITY_ENCRYPTION_TRANSPORT - #define f_socket_option_select_error_queue_d SO_SELECT_ERR_QUEUE - #define f_socket_option_time_out_receive_d SO_RCVTIMEO - #define f_socket_option_time_out_send_d SO_SNDTIMEO - #define f_socket_option_time_stamp_d SO_TIMESTAMP - #define f_socket_option_time_stamp_namespace_d SO_TIMESTAMPNS - #define f_socket_option_time_stamping_d SO_TIMESTAMPING - #define f_socket_option_time_stamping_packet_d SCM_TIMESTAMPING_PKTINFO - #define f_socket_option_time_stamping_stats_d SCM_TIMESTAMPING_OPT_STATS - #define f_socket_option_time_transmit_d SO_TXTIME - #define f_socket_option_type_d SO_TYPE - #define f_socket_option_wifi_status_d SO_WIFI_STATUS - #define f_socket_option_zero_copy_d SO_ZEROCOPY -#endif // _di_f_socket_option_d_ +#ifndef _di_f_socket_option_e_ + enum { + f_socket_option_address_reuse_e = SO_REUSEADDR, + f_socket_option_advice_cnx_e = SO_CNX_ADVICE, + f_socket_option_bpf_attach_e = SO_ATTACH_BPF, + f_socket_option_bpf_detach_e = SO_DETACH_BPF, + f_socket_option_bpf_extensions_e = SO_BPF_EXTENSIONS, + f_socket_option_broadcast_e = SO_BROADCAST, + f_socket_option_buffer_receive_e = SO_RCVBUF, + f_socket_option_buffer_receive_force_e = SO_RCVBUFFORCE, + f_socket_option_buffer_send_e = SO_SNDBUF, + f_socket_option_buffer_send_force_e = SO_SNDBUFFORCE, + f_socket_option_cbpf_port_reuse_attach_e = SO_ATTACH_REUSEPORT_CBPF, + f_socket_option_check_not_e = SO_NO_CHECK, + f_socket_option_compatibility_bsd_e = SO_BSDCOMPAT, + f_socket_option_connection_accept_e = SO_ACCEPTCONN, + f_socket_option_cookie_e = SO_COOKIE, + f_socket_option_cpu_incoming_e = SO_INCOMING_CPU, + f_socket_option_credentials_pass_e = SO_PASSCRED, + f_socket_option_credentials_peer_e = SO_PEERCRED, + f_socket_option_debug_e = SO_DEBUG, + f_socket_option_device_bind_e = SO_BINDTODEVICE, + f_socket_option_domain_e = SO_DOMAIN, + f_socket_option_ebpf_port_reuse_attach_e = SO_ATTACH_REUSEPORT_EBPF, + f_socket_option_error_e = SO_ERROR, + f_socket_option_filter_attach_e = SO_ATTACH_FILTER, + f_socket_option_filter_detach_e = SO_DETACH_FILTER, + f_socket_option_filter_get_e = SO_GET_FILTER, + f_socket_option_filter_lock_e = SO_LOCK_FILTER, + f_socket_option_frame_check_sequence_not_e = SO_NOFCS, + f_socket_option_groups_peer_e = SO_PEERGROUPS, + f_socket_option_keep_alive_e = SO_KEEPALIVE, + f_socket_option_linger_e = SO_LINGER, + f_socket_option_low_at_receive_e = SO_RCVLOWAT, + f_socket_option_low_at_send_e = SO_SNDLOWAT, + f_socket_option_mark_e = SO_MARK, + f_socket_option_memory_information_e = SO_MEMINFO, + f_socket_option_name_peer_e = SO_PEERNAME, + f_socket_option_napi_id_incoming_e = SO_INCOMING_NAPI_ID, + f_socket_option_out_of_band_inline_e = SO_OOBINLINE, + f_socket_option_pacing_rate_max_e = SO_MAX_PACING_RATE, + f_socket_option_peek_off_e = SO_PEEK_OFF, + f_socket_option_poll_busy_e = SO_BUSY_POLL, + f_socket_option_port_reuse_e = SO_REUSEPORT, + f_socket_option_priority_e = SO_PRIORITY, + f_socket_option_protocol_e = SO_PROTOCOL, + f_socket_option_receive_overflow_e = SO_RXQ_OVFL, + f_socket_option_route_not_e = SO_DONTROUTE, + f_socket_option_security_authentication_e = SO_SECURITY_AUTHENTICATION, + f_socket_option_security_network_e = SO_SECURITY_ENCRYPTION_NETWORK, + f_socket_option_security_pass_e = SO_PASSSEC, + f_socket_option_security_peer_e = SO_PEERSEC, + f_socket_option_security_transport_e = SO_SECURITY_ENCRYPTION_TRANSPORT, + f_socket_option_select_error_queue_e = SO_SELECT_ERR_QUEUE, + f_socket_option_time_out_receive_e = SO_RCVTIMEO, + f_socket_option_time_out_send_e = SO_SNDTIMEO, + f_socket_option_time_stamp_e = SO_TIMESTAMP, + f_socket_option_time_stamp_namespace_e = SO_TIMESTAMPNS, + f_socket_option_time_stamping_e = SO_TIMESTAMPING, + f_socket_option_time_stamping_packet_e = SCM_TIMESTAMPING_PKTINFO, + f_socket_option_time_stamping_stats_e = SCM_TIMESTAMPING_OPT_STATS, + f_socket_option_time_transmit_e = SO_TXTIME, + f_socket_option_type_e = SO_TYPE, + f_socket_option_wifi_status_e = SO_WIFI_STATUS, + f_socket_option_zero_copy_e = SO_ZEROCOPY, + }; +#endif // _di_f_socket_option_e_ /** * Socket Flags. * * These are flags to pass to either socket receive or socket send functions. * - * f_socket_flag_*: + * 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. @@ -229,45 +527,49 @@ extern "C" { * - wait_all: Block until the full request is satisfied. * - wait_not: Use non-blocking. */ -#ifndef _di_f_socket_flag_d_ - #define f_socket_flag_close_on_exit_d MSG_CMSG_CLOEXEC - #define f_socket_flag_confirm_d MSG_CONFIRM - #define f_socket_flag_error_queue_d MSG_ERRQUEUE - #define f_socket_flag_more_d MSG_MORE - #define f_socket_flag_out_of_band_d MSG_OOB - #define f_socket_flag_peek_d MSG_PEEK - #define f_socket_flag_record_end_d MSG_EOR - #define f_socket_flag_route_not_d MSG_DONTROUTE - #define f_socket_flag_signal_not_d MSG_NOSIGNAL - #define f_socket_flag_truncate_d MSG_TRUNC - #define f_socket_flag_wait_all_d MSG_WAITALL - #define f_socket_flag_wait_not_d MSG_DONTWAIT -#endif // _di_f_socket_flag_d_ +#ifndef _di_f_socket_flag_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, + }; +#endif // _di_f_socket_flag_e_ /** * Socket Message Flags. * * These represent responses from socket messages (see recvmsg()). * - * f_socket_message_flag_*: + * 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_d_ - #define f_socket_message_flag_error_queue_d MSG_ERRQUEUE - #define f_socket_message_flag_out_of_band_d MSG_OOB - #define f_socket_message_flag_record_end_d MSG_EOR - #define f_socket_message_flag_truncate_d MSG_TRUNC - #define f_socket_message_flag_truncate_control_d MSG_CTRUNC -#endif // _di_f_socket_flag_d_ +#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 types. * - * f_socket_type_*: + * f_socket_type_*_e: * - close_on_execute: Close on execute. * - datagram: Datagram (connectionless, unreliable, fixed length). * - datagram_reliable: Reliable Datagram (reliable variant of datagram, unordered) @@ -276,15 +578,17 @@ extern "C" { * - raw: Raw access. * - stream: Stream. */ -#ifndef _di_f_socket_type_d_ - #define f_socket_type_close_on_execute_d SOCK_CLOEXEC - #define f_socket_type_datagram_d SOCK_DGRAM - #define f_socket_type_datagram_reliable_d SOCK_RDM - #define f_socket_type_datagram_sequence_d SOCK_SEQPACKET - #define f_socket_type_nonblocking_d SOCK_NONBLOCK - #define f_socket_type_raw_d SOCK_RAW - #define f_socket_type_stream_d SOCK_STREAM -#endif // _di_f_socket_type_d_ +#ifndef _di_f_socket_type_e_ + enum { + f_socket_type_close_on_execute_e = SOCK_CLOEXEC, + f_socket_type_datagram_e = SOCK_DGRAM, + f_socket_type_datagram_reliable_e = SOCK_RDM, + f_socket_type_datagram_sequence_e = SOCK_SEQPACKET, + f_socket_type_nonblocking_e = SOCK_NONBLOCK, + f_socket_type_raw_e = SOCK_RAW, + f_socket_type_stream_e = SOCK_STREAM, + }; +#endif // _di_f_socket_type_e_ /** * Commonly used socket related properties, loosely based off of f_file_t. @@ -292,7 +596,7 @@ extern "C" { * id: File descriptor, with a value of -1 represents a closed file. * domain: The socket domain (protocol family). * protocol: The socket protocol. - * type: The socket type. + * type: The socket type (address family). * * size_read: The default number of 1-byte characters to read at a time and is often used for the read buffer size. * size_write: The default number of 1-byte characters to read at a time and is often used for the write buffer size. diff --git a/level_0/f_socket/tests/unit/c/test-socket-bind_local.c b/level_0/f_socket/tests/unit/c/test-socket-bind_local.c index f5968c8..cf306a6 100644 --- a/level_0/f_socket/tests/unit/c/test-socket-bind_local.c +++ b/level_0/f_socket/tests/unit/c/test-socket-bind_local.c @@ -43,7 +43,7 @@ void test__f_socket_bind_local__fails(void **state) { memset(&address, 0, sizeof(struct sockaddr_un)); - address.sun_family = f_socket_domain_file_d; + address.sun_family = f_socket_protocol_family_local_e; socket.address = (struct sockaddr *) &address; @@ -61,10 +61,10 @@ void test__f_socket_bind_local__fails(void **state) { memset(&address, 0, sizeof(struct sockaddr_un)); - address.sun_family = f_socket_domain_file_d; + address.sun_family = f_socket_protocol_family_local_e; socket.address = (struct sockaddr *) &address; - socket.domain = f_socket_domain_file_d; + socket.domain = f_socket_protocol_family_local_e; for (uint8_t i = 0; i < 12; ++i) { @@ -95,10 +95,10 @@ void test__f_socket_bind_local__works(void **state) { memset(&address, 0, sizeof(struct sockaddr_un)); - address.sun_family = f_socket_domain_file_d; + address.sun_family = f_socket_protocol_family_local_e; socket.address = (struct sockaddr *) &address; - socket.domain = f_socket_domain_file_d; + socket.domain = f_socket_protocol_family_local_e; will_return(__wrap_bind, false); diff --git a/level_3/control/c/control.c b/level_3/control/c/control.c index bd56112..c5bf299 100644 --- a/level_3/control/c/control.c +++ b/level_3/control/c/control.c @@ -148,7 +148,7 @@ extern "C" { memset(&socket_address, 0, sizeof(struct sockaddr_un)); data.socket.address = (struct sockaddr *) &socket_address; - data.socket.domain = f_socket_domain_file_d; + data.socket.domain = f_socket_protocol_family_local_e; data.socket.type = f_socket_type_stream_d; data.socket.length = sizeof(struct sockaddr_un); diff --git a/level_3/control/c/private-control.c b/level_3/control/c/private-control.c index 11281e6..20a480c 100644 --- a/level_3/control/c/private-control.c +++ b/level_3/control/c/private-control.c @@ -293,7 +293,7 @@ extern "C" { memset(head, 0, sizeof(uint8_t) * length); - status = f_socket_read(&data->socket, f_socket_flag_peek_d, (void *) head, &length); + status = f_socket_read(&data->socket, f_socket_flag_peek_e, (void *) head, &length); if (F_status_is_error(status)) return status; if (length < 5) return F_status_set_error(F_packet_not); @@ -311,7 +311,7 @@ extern "C" { status = f_string_dynamic_increase_by(length, &data->cache.large); if (F_status_is_error(status)) return status; - status = f_socket_read(&data->socket, f_socket_flag_wait_all_d, (void *) head, &length); + status = f_socket_read(&data->socket, f_socket_flag_wait_all_e, (void *) head, &length); if (F_status_is_error(status)) return status; if (length < data->cache.large.used) return F_status_set_error(F_too_small); if (length > data->cache.large.used) return F_status_set_error(F_too_large); diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index 3aec018..854bc36 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -97,7 +97,7 @@ extern "C" { controller_setting_t setting = controller_setting_t_initialize; setting.control.server.address = (struct sockaddr *) &setting.control.address; - setting.control.server.domain = f_socket_domain_file_d; + setting.control.server.domain = f_socket_protocol_family_local_e; setting.control.server.type = f_socket_type_stream_d; setting.control.server.length = sizeof(struct sockaddr_un); -- 1.8.3.1