Skip to content

std.net : Add a condition in parseIp4 function to check for localhost in the address #5471

@palash25

Description

@palash25

Hi, new to zig, started learning a few days ago, was playing around with it trying to connect to tcp server and I kept getting an error for my code which looked roughly like this

    var port: u16 = 6379;
    var addr = "localhost";
    var conn = try std.net.tcpConnectToAddress(try net.Address.parseIp4(addr, port));

the error said InvalidCharacter so I had to do a little digging and saw that while parsing the address the code was looking for "." which gave me the clue to use 127.0.0.1 instead of localhost and my code worked.

The TCP libraries that I have played around with in other languages accept both 127.0.0.1 and localhost I was wondering it it would be possible to add a condition to check for "localhost" in parseIp4 function.

Let me know if you would like a PR for this. 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions