Skip to content

Conversation

Copy link

Copilot AI commented Jan 2, 2026

Addresses question about why comparison results shouldn't be used directly in socket address family assignment.

Context

The code uses a ternary operator to select between AF_INET6 (10) and AF_INET (2):

int domain = (strcmp(IP_VERSION, "IPv6") == 0) ? AF_INET6 : AF_INET;
server_address.sin_family = domain;
inet_pton(domain, SERVER_IP, &server_address.sin_addr);

Clarification

  • Current implementation is correct: The comparison result (0 or 1) is not used directly; the ternary operator selects the appropriate constant
  • Direct use would fail: strcmp(...) == 0 yields 0 or 1, which don't match AF_INET (2) or AF_INET6 (10)
  • No changes needed: The original review comment was based on a misunderstanding

The distinction matters because socket APIs require specific constant values, not boolean results.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update comparison result usage in server/client implementation clarify: Explain why ternary operator correctly selects address family constants Jan 2, 2026
Copilot AI requested a review from Satorien January 2, 2026 15:20
@Satorien Satorien closed this Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants