Hi.
So i have strings of an ip address, e.g. 192.168.0.1
I need to get that converted into a 8bit int so 192.168.0.1 would turn into 3232235521
You might think, how does he know what that int is? good question, my coworker managed to get it right in perl.
#! /usr/bin/perl -w
use strict;
use Socket;
my $ip=$ARGV[0];
my $n_ip=inet_aton("$ip");
my $u_ip=unpack("N", $n_ip);
print "IP: $ip - U_IP: $u_ip\n";
So i have something to reference.
My postgres database has the datatype int8, this is what i have so far (and i feel i have tried so many things).
type Host struct {
DhcpIdentifier []byte
DhcpIdentifierType int
Dhcp4SubnetId int
Ipv4Address int `gorm:"type:inet"`
Hostname string
}
payload := res.Payload.Results[0]
ipv4 := *(payload.PrimaryIp4.Address)
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=5432",
viper.GetString("psql.hostname"),
viper.GetString("psql.username"),
viper.GetString("psql.password"),
viper.GetString("psql.db"))
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
log.Error(err)
os.Exit(0)
}
result := db.Create(&Host{
DhcpIdentifier: mac,
DhcpIdentifierType: 0,
Dhcp4SubnetId: subnet,
Ipv4Address: ipv4,
Hostname: Name,
})
if result.Error != nil {
log.Error(result.Error)
os.Exit(0)
}

already knew it was ugly and kinda stupid