id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
19,300 | containers/storage | drivers/copy/copy_unsupported.go | DirCopy | func DirCopy(srcDir, dstDir string, _ Mode, _ bool) error {
return chrootarchive.NewArchiver(nil).CopyWithTar(srcDir, dstDir)
} | go | func DirCopy(srcDir, dstDir string, _ Mode, _ bool) error {
return chrootarchive.NewArchiver(nil).CopyWithTar(srcDir, dstDir)
} | [
"func",
"DirCopy",
"(",
"srcDir",
",",
"dstDir",
"string",
",",
"_",
"Mode",
",",
"_",
"bool",
")",
"error",
"{",
"return",
"chrootarchive",
".",
"NewArchiver",
"(",
"nil",
")",
".",
"CopyWithTar",
"(",
"srcDir",
",",
"dstDir",
")",
"\n",
"}"
] | // DirCopy copies or hardlinks the contents of one directory to another,
// properly handling soft links | [
"DirCopy",
"copies",
"or",
"hardlinks",
"the",
"contents",
"of",
"one",
"directory",
"to",
"another",
"properly",
"handling",
"soft",
"links"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/copy/copy_unsupported.go#L17-L19 |
19,301 | containers/storage | drivers/driver_solaris.go | Mounted | func Mounted(fsType FsMagic, mountPath string) (bool, error) {
cs := C.CString(filepath.Dir(mountPath))
defer C.free(unsafe.Pointer(cs))
buf := C.getstatfs(cs)
defer C.free(unsafe.Pointer(buf))
// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
(buf.f_basetype[3] != 0) {
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
return false, ErrPrerequisites
}
return true, nil
} | go | func Mounted(fsType FsMagic, mountPath string) (bool, error) {
cs := C.CString(filepath.Dir(mountPath))
defer C.free(unsafe.Pointer(cs))
buf := C.getstatfs(cs)
defer C.free(unsafe.Pointer(buf))
// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
(buf.f_basetype[3] != 0) {
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
return false, ErrPrerequisites
}
return true, nil
} | [
"func",
"Mounted",
"(",
"fsType",
"FsMagic",
",",
"mountPath",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"filepath",
".",
"Dir",
"(",
"mountPath",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsa... | // Mounted checks if the given path is mounted as the fs type
//Solaris supports only ZFS for now | [
"Mounted",
"checks",
"if",
"the",
"given",
"path",
"is",
"mounted",
"as",
"the",
"fs",
"type",
"Solaris",
"supports",
"only",
"ZFS",
"for",
"now"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/driver_solaris.go#L81-L96 |
19,302 | containers/storage | lockfile_linux.go | TouchedSince | func (l *lockfile) TouchedSince(when time.Time) bool {
st := unix.Stat_t{}
err := unix.Fstat(int(l.fd), &st)
if err != nil {
return true
}
touched := time.Unix(st.Mtim.Unix())
return when.Before(touched)
} | go | func (l *lockfile) TouchedSince(when time.Time) bool {
st := unix.Stat_t{}
err := unix.Fstat(int(l.fd), &st)
if err != nil {
return true
}
touched := time.Unix(st.Mtim.Unix())
return when.Before(touched)
} | [
"func",
"(",
"l",
"*",
"lockfile",
")",
"TouchedSince",
"(",
"when",
"time",
".",
"Time",
")",
"bool",
"{",
"st",
":=",
"unix",
".",
"Stat_t",
"{",
"}",
"\n",
"err",
":=",
"unix",
".",
"Fstat",
"(",
"int",
"(",
"l",
".",
"fd",
")",
",",
"&",
... | // TouchedSince indicates if the lock file has been touched since the specified time | [
"TouchedSince",
"indicates",
"if",
"the",
"lock",
"file",
"has",
"been",
"touched",
"since",
"the",
"specified",
"time"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/lockfile_linux.go#L12-L20 |
19,303 | containers/storage | pkg/archive/archive.go | NewDefaultArchiver | func NewDefaultArchiver() *Archiver {
return &Archiver{Untar: Untar, TarIDMappings: &idtools.IDMappings{}, UntarIDMappings: &idtools.IDMappings{}}
} | go | func NewDefaultArchiver() *Archiver {
return &Archiver{Untar: Untar, TarIDMappings: &idtools.IDMappings{}, UntarIDMappings: &idtools.IDMappings{}}
} | [
"func",
"NewDefaultArchiver",
"(",
")",
"*",
"Archiver",
"{",
"return",
"&",
"Archiver",
"{",
"Untar",
":",
"Untar",
",",
"TarIDMappings",
":",
"&",
"idtools",
".",
"IDMappings",
"{",
"}",
",",
"UntarIDMappings",
":",
"&",
"idtools",
".",
"IDMappings",
"{"... | // NewDefaultArchiver returns a new Archiver without any IDMappings | [
"NewDefaultArchiver",
"returns",
"a",
"new",
"Archiver",
"without",
"any",
"IDMappings"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L83-L85 |
19,304 | containers/storage | pkg/archive/archive.go | NewArchiver | func NewArchiver(idMappings *idtools.IDMappings) *Archiver {
if idMappings == nil {
idMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMappings: idMappings, UntarIDMappings: idMappings}
} | go | func NewArchiver(idMappings *idtools.IDMappings) *Archiver {
if idMappings == nil {
idMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMappings: idMappings, UntarIDMappings: idMappings}
} | [
"func",
"NewArchiver",
"(",
"idMappings",
"*",
"idtools",
".",
"IDMappings",
")",
"*",
"Archiver",
"{",
"if",
"idMappings",
"==",
"nil",
"{",
"idMappings",
"=",
"&",
"idtools",
".",
"IDMappings",
"{",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Archiver",
"{",... | // NewArchiver returns a new Archiver | [
"NewArchiver",
"returns",
"a",
"new",
"Archiver"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L1338-L1343 |
19,305 | containers/storage | pkg/archive/archive.go | NewArchiverWithChown | func NewArchiverWithChown(tarIDMappings *idtools.IDMappings, chownOpts *idtools.IDPair, untarIDMappings *idtools.IDMappings) *Archiver {
if tarIDMappings == nil {
tarIDMappings = &idtools.IDMappings{}
}
if untarIDMappings == nil {
untarIDMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMappings: tarIDMappings, ChownOpts: chownOpts, UntarIDMappings: untarIDMappings}
} | go | func NewArchiverWithChown(tarIDMappings *idtools.IDMappings, chownOpts *idtools.IDPair, untarIDMappings *idtools.IDMappings) *Archiver {
if tarIDMappings == nil {
tarIDMappings = &idtools.IDMappings{}
}
if untarIDMappings == nil {
untarIDMappings = &idtools.IDMappings{}
}
return &Archiver{Untar: Untar, TarIDMappings: tarIDMappings, ChownOpts: chownOpts, UntarIDMappings: untarIDMappings}
} | [
"func",
"NewArchiverWithChown",
"(",
"tarIDMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"chownOpts",
"*",
"idtools",
".",
"IDPair",
",",
"untarIDMappings",
"*",
"idtools",
".",
"IDMappings",
")",
"*",
"Archiver",
"{",
"if",
"tarIDMappings",
"==",
"nil",
... | // NewArchiverWithChown returns a new Archiver which uses Untar and the provided ID mapping configuration on both ends | [
"NewArchiverWithChown",
"returns",
"a",
"new",
"Archiver",
"which",
"uses",
"Untar",
"and",
"the",
"provided",
"ID",
"mapping",
"configuration",
"on",
"both",
"ends"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L1346-L1354 |
19,306 | containers/storage | pkg/archive/archive.go | TarPath | func TarPath(uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(path string) (io.ReadCloser, error) {
tarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
return func(path string) (io.ReadCloser, error) {
return TarWithOptions(path, &TarOptions{
Compression: Uncompressed,
UIDMaps: tarMappings.UIDs(),
GIDMaps: tarMappings.GIDs(),
})
}
} | go | func TarPath(uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(path string) (io.ReadCloser, error) {
tarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
return func(path string) (io.ReadCloser, error) {
return TarWithOptions(path, &TarOptions{
Compression: Uncompressed,
UIDMaps: tarMappings.UIDs(),
GIDMaps: tarMappings.GIDs(),
})
}
} | [
"func",
"TarPath",
"(",
"uidmap",
"[",
"]",
"idtools",
".",
"IDMap",
",",
"gidmap",
"[",
"]",
"idtools",
".",
"IDMap",
")",
"func",
"(",
"path",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"tarMappings",
":=",
"idtools",
".",... | // TarPath returns a function which creates an archive of a specified
// location in the container's filesystem, mapping permissions using the
// container's ID maps | [
"TarPath",
"returns",
"a",
"function",
"which",
"creates",
"an",
"archive",
"of",
"a",
"specified",
"location",
"in",
"the",
"container",
"s",
"filesystem",
"mapping",
"permissions",
"using",
"the",
"container",
"s",
"ID",
"maps"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/archive.go#L1431-L1440 |
19,307 | Masterminds/semver | version.go | NewVersion | func NewVersion(v string) (*Version, error) {
m := versionRegex.FindStringSubmatch(v)
if m == nil {
return nil, ErrInvalidSemVer
}
sv := &Version{
metadata: m[8],
pre: m[5],
original: v,
}
var temp int64
temp, err := strconv.ParseInt(m[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing version segment: %s", err)
}
sv.major = temp
if m[2] != "" {
temp, err = strconv.ParseInt(strings.TrimPrefix(m[2], "."), 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing version segment: %s", err)
}
sv.minor = temp
} else {
sv.minor = 0
}
if m[3] != "" {
temp, err = strconv.ParseInt(strings.TrimPrefix(m[3], "."), 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing version segment: %s", err)
}
sv.patch = temp
} else {
sv.patch = 0
}
return sv, nil
} | go | func NewVersion(v string) (*Version, error) {
m := versionRegex.FindStringSubmatch(v)
if m == nil {
return nil, ErrInvalidSemVer
}
sv := &Version{
metadata: m[8],
pre: m[5],
original: v,
}
var temp int64
temp, err := strconv.ParseInt(m[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing version segment: %s", err)
}
sv.major = temp
if m[2] != "" {
temp, err = strconv.ParseInt(strings.TrimPrefix(m[2], "."), 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing version segment: %s", err)
}
sv.minor = temp
} else {
sv.minor = 0
}
if m[3] != "" {
temp, err = strconv.ParseInt(strings.TrimPrefix(m[3], "."), 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing version segment: %s", err)
}
sv.patch = temp
} else {
sv.patch = 0
}
return sv, nil
} | [
"func",
"NewVersion",
"(",
"v",
"string",
")",
"(",
"*",
"Version",
",",
"error",
")",
"{",
"m",
":=",
"versionRegex",
".",
"FindStringSubmatch",
"(",
"v",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrInvalidSemVer",
"\n",
"}",
"... | // NewVersion parses a given version and returns an instance of Version or
// an error if unable to parse the version. | [
"NewVersion",
"parses",
"a",
"given",
"version",
"and",
"returns",
"an",
"instance",
"of",
"Version",
"or",
"an",
"error",
"if",
"unable",
"to",
"parse",
"the",
"version",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L54-L94 |
19,308 | Masterminds/semver | version.go | MustParse | func MustParse(v string) *Version {
sv, err := NewVersion(v)
if err != nil {
panic(err)
}
return sv
} | go | func MustParse(v string) *Version {
sv, err := NewVersion(v)
if err != nil {
panic(err)
}
return sv
} | [
"func",
"MustParse",
"(",
"v",
"string",
")",
"*",
"Version",
"{",
"sv",
",",
"err",
":=",
"NewVersion",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"sv",
"\n",
"}"
] | // MustParse parses a given version and panics on error. | [
"MustParse",
"parses",
"a",
"given",
"version",
"and",
"panics",
"on",
"error",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L97-L103 |
19,309 | Masterminds/semver | version.go | originalVPrefix | func (v *Version) originalVPrefix() string {
// Note, only lowercase v is supported as a prefix by the parser.
if v.original != "" && v.original[:1] == "v" {
return v.original[:1]
}
return ""
} | go | func (v *Version) originalVPrefix() string {
// Note, only lowercase v is supported as a prefix by the parser.
if v.original != "" && v.original[:1] == "v" {
return v.original[:1]
}
return ""
} | [
"func",
"(",
"v",
"*",
"Version",
")",
"originalVPrefix",
"(",
")",
"string",
"{",
"// Note, only lowercase v is supported as a prefix by the parser.",
"if",
"v",
".",
"original",
"!=",
"\"",
"\"",
"&&",
"v",
".",
"original",
"[",
":",
"1",
"]",
"==",
"\"",
... | // originalVPrefix returns the original 'v' prefix if any. | [
"originalVPrefix",
"returns",
"the",
"original",
"v",
"prefix",
"if",
"any",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L155-L162 |
19,310 | Masterminds/semver | version.go | IncMinor | func (v Version) IncMinor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = v.minor + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | go | func (v Version) IncMinor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = v.minor + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | [
"func",
"(",
"v",
"Version",
")",
"IncMinor",
"(",
")",
"Version",
"{",
"vNext",
":=",
"v",
"\n",
"vNext",
".",
"metadata",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"pre",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"patch",
"=",
"0",
"\n",
"vNext",
".",
... | // IncMinor produces the next minor version.
// Sets patch to 0.
// Increments minor number.
// Unsets metadata.
// Unsets prerelease status. | [
"IncMinor",
"produces",
"the",
"next",
"minor",
"version",
".",
"Sets",
"patch",
"to",
"0",
".",
"Increments",
"minor",
"number",
".",
"Unsets",
"metadata",
".",
"Unsets",
"prerelease",
"status",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L192-L200 |
19,311 | Masterminds/semver | version.go | IncMajor | func (v Version) IncMajor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = 0
vNext.major = v.major + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | go | func (v Version) IncMajor() Version {
vNext := v
vNext.metadata = ""
vNext.pre = ""
vNext.patch = 0
vNext.minor = 0
vNext.major = v.major + 1
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext
} | [
"func",
"(",
"v",
"Version",
")",
"IncMajor",
"(",
")",
"Version",
"{",
"vNext",
":=",
"v",
"\n",
"vNext",
".",
"metadata",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"pre",
"=",
"\"",
"\"",
"\n",
"vNext",
".",
"patch",
"=",
"0",
"\n",
"vNext",
".",
... | // IncMajor produces the next major version.
// Sets patch to 0.
// Sets minor to 0.
// Increments major number.
// Unsets metadata.
// Unsets prerelease status. | [
"IncMajor",
"produces",
"the",
"next",
"major",
"version",
".",
"Sets",
"patch",
"to",
"0",
".",
"Sets",
"minor",
"to",
"0",
".",
"Increments",
"major",
"number",
".",
"Unsets",
"metadata",
".",
"Unsets",
"prerelease",
"status",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L208-L217 |
19,312 | Masterminds/semver | version.go | SetPrerelease | func (v Version) SetPrerelease(prerelease string) (Version, error) {
vNext := v
if len(prerelease) > 0 && !validPrereleaseRegex.MatchString(prerelease) {
return vNext, ErrInvalidPrerelease
}
vNext.pre = prerelease
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | go | func (v Version) SetPrerelease(prerelease string) (Version, error) {
vNext := v
if len(prerelease) > 0 && !validPrereleaseRegex.MatchString(prerelease) {
return vNext, ErrInvalidPrerelease
}
vNext.pre = prerelease
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | [
"func",
"(",
"v",
"Version",
")",
"SetPrerelease",
"(",
"prerelease",
"string",
")",
"(",
"Version",
",",
"error",
")",
"{",
"vNext",
":=",
"v",
"\n",
"if",
"len",
"(",
"prerelease",
")",
">",
"0",
"&&",
"!",
"validPrereleaseRegex",
".",
"MatchString",
... | // SetPrerelease defines the prerelease value.
// Value must not include the required 'hypen' prefix. | [
"SetPrerelease",
"defines",
"the",
"prerelease",
"value",
".",
"Value",
"must",
"not",
"include",
"the",
"required",
"hypen",
"prefix",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L221-L229 |
19,313 | Masterminds/semver | version.go | SetMetadata | func (v Version) SetMetadata(metadata string) (Version, error) {
vNext := v
if len(metadata) > 0 && !validPrereleaseRegex.MatchString(metadata) {
return vNext, ErrInvalidMetadata
}
vNext.metadata = metadata
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | go | func (v Version) SetMetadata(metadata string) (Version, error) {
vNext := v
if len(metadata) > 0 && !validPrereleaseRegex.MatchString(metadata) {
return vNext, ErrInvalidMetadata
}
vNext.metadata = metadata
vNext.original = v.originalVPrefix() + "" + vNext.String()
return vNext, nil
} | [
"func",
"(",
"v",
"Version",
")",
"SetMetadata",
"(",
"metadata",
"string",
")",
"(",
"Version",
",",
"error",
")",
"{",
"vNext",
":=",
"v",
"\n",
"if",
"len",
"(",
"metadata",
")",
">",
"0",
"&&",
"!",
"validPrereleaseRegex",
".",
"MatchString",
"(",
... | // SetMetadata defines metadata value.
// Value must not include the required 'plus' prefix. | [
"SetMetadata",
"defines",
"metadata",
"value",
".",
"Value",
"must",
"not",
"include",
"the",
"required",
"plus",
"prefix",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L233-L241 |
19,314 | Masterminds/semver | version.go | Compare | func (v *Version) Compare(o *Version) int {
// Compare the major, minor, and patch version for differences. If a
// difference is found return the comparison.
if d := compareSegment(v.Major(), o.Major()); d != 0 {
return d
}
if d := compareSegment(v.Minor(), o.Minor()); d != 0 {
return d
}
if d := compareSegment(v.Patch(), o.Patch()); d != 0 {
return d
}
// At this point the major, minor, and patch versions are the same.
ps := v.pre
po := o.Prerelease()
if ps == "" && po == "" {
return 0
}
if ps == "" {
return 1
}
if po == "" {
return -1
}
return comparePrerelease(ps, po)
} | go | func (v *Version) Compare(o *Version) int {
// Compare the major, minor, and patch version for differences. If a
// difference is found return the comparison.
if d := compareSegment(v.Major(), o.Major()); d != 0 {
return d
}
if d := compareSegment(v.Minor(), o.Minor()); d != 0 {
return d
}
if d := compareSegment(v.Patch(), o.Patch()); d != 0 {
return d
}
// At this point the major, minor, and patch versions are the same.
ps := v.pre
po := o.Prerelease()
if ps == "" && po == "" {
return 0
}
if ps == "" {
return 1
}
if po == "" {
return -1
}
return comparePrerelease(ps, po)
} | [
"func",
"(",
"v",
"*",
"Version",
")",
"Compare",
"(",
"o",
"*",
"Version",
")",
"int",
"{",
"// Compare the major, minor, and patch version for differences. If a",
"// difference is found return the comparison.",
"if",
"d",
":=",
"compareSegment",
"(",
"v",
".",
"Major... | // Compare compares this version to another one. It returns -1, 0, or 1 if
// the version smaller, equal, or larger than the other version.
//
// Versions are compared by X.Y.Z. Build metadata is ignored. Prerelease is
// lower than the version without a prerelease. | [
"Compare",
"compares",
"this",
"version",
"to",
"another",
"one",
".",
"It",
"returns",
"-",
"1",
"0",
"or",
"1",
"if",
"the",
"version",
"smaller",
"equal",
"or",
"larger",
"than",
"the",
"other",
"version",
".",
"Versions",
"are",
"compared",
"by",
"X"... | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L265-L293 |
19,315 | Masterminds/semver | version.go | UnmarshalJSON | func (v *Version) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
temp, err := NewVersion(s)
if err != nil {
return err
}
v.major = temp.major
v.minor = temp.minor
v.patch = temp.patch
v.pre = temp.pre
v.metadata = temp.metadata
v.original = temp.original
temp = nil
return nil
} | go | func (v *Version) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
temp, err := NewVersion(s)
if err != nil {
return err
}
v.major = temp.major
v.minor = temp.minor
v.patch = temp.patch
v.pre = temp.pre
v.metadata = temp.metadata
v.original = temp.original
temp = nil
return nil
} | [
"func",
"(",
"v",
"*",
"Version",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"s",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return"... | // UnmarshalJSON implements JSON.Unmarshaler interface. | [
"UnmarshalJSON",
"implements",
"JSON",
".",
"Unmarshaler",
"interface",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/version.go#L296-L313 |
19,316 | Masterminds/semver | constraints.go | NewConstraint | func NewConstraint(c string) (*Constraints, error) {
// Rewrite - ranges into a comparison operation.
c = rewriteRange(c)
ors := strings.Split(c, "||")
or := make([][]*constraint, len(ors))
for k, v := range ors {
cs := strings.Split(v, ",")
result := make([]*constraint, len(cs))
for i, s := range cs {
pc, err := parseConstraint(s)
if err != nil {
return nil, err
}
result[i] = pc
}
or[k] = result
}
o := &Constraints{constraints: or}
return o, nil
} | go | func NewConstraint(c string) (*Constraints, error) {
// Rewrite - ranges into a comparison operation.
c = rewriteRange(c)
ors := strings.Split(c, "||")
or := make([][]*constraint, len(ors))
for k, v := range ors {
cs := strings.Split(v, ",")
result := make([]*constraint, len(cs))
for i, s := range cs {
pc, err := parseConstraint(s)
if err != nil {
return nil, err
}
result[i] = pc
}
or[k] = result
}
o := &Constraints{constraints: or}
return o, nil
} | [
"func",
"NewConstraint",
"(",
"c",
"string",
")",
"(",
"*",
"Constraints",
",",
"error",
")",
"{",
"// Rewrite - ranges into a comparison operation.",
"c",
"=",
"rewriteRange",
"(",
"c",
")",
"\n\n",
"ors",
":=",
"strings",
".",
"Split",
"(",
"c",
",",
"\"",... | // NewConstraint returns a Constraints instance that a Version instance can
// be checked against. If there is a parse error it will be returned. | [
"NewConstraint",
"returns",
"a",
"Constraints",
"instance",
"that",
"a",
"Version",
"instance",
"can",
"be",
"checked",
"against",
".",
"If",
"there",
"is",
"a",
"parse",
"error",
"it",
"will",
"be",
"returned",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L18-L41 |
19,317 | Masterminds/semver | constraints.go | Check | func (cs Constraints) Check(v *Version) bool {
// loop over the ORs and check the inner ANDs
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
joy = false
break
}
}
if joy {
return true
}
}
return false
} | go | func (cs Constraints) Check(v *Version) bool {
// loop over the ORs and check the inner ANDs
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
joy = false
break
}
}
if joy {
return true
}
}
return false
} | [
"func",
"(",
"cs",
"Constraints",
")",
"Check",
"(",
"v",
"*",
"Version",
")",
"bool",
"{",
"// loop over the ORs and check the inner ANDs",
"for",
"_",
",",
"o",
":=",
"range",
"cs",
".",
"constraints",
"{",
"joy",
":=",
"true",
"\n",
"for",
"_",
",",
"... | // Check tests if a version satisfies the constraints. | [
"Check",
"tests",
"if",
"a",
"version",
"satisfies",
"the",
"constraints",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L44-L61 |
19,318 | Masterminds/semver | constraints.go | Validate | func (cs Constraints) Validate(v *Version) (bool, []error) {
// loop over the ORs and check the inner ANDs
var e []error
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
em := fmt.Errorf(c.msg, v, c.orig)
e = append(e, em)
joy = false
}
}
if joy {
return true, []error{}
}
}
return false, e
} | go | func (cs Constraints) Validate(v *Version) (bool, []error) {
// loop over the ORs and check the inner ANDs
var e []error
for _, o := range cs.constraints {
joy := true
for _, c := range o {
if !c.check(v) {
em := fmt.Errorf(c.msg, v, c.orig)
e = append(e, em)
joy = false
}
}
if joy {
return true, []error{}
}
}
return false, e
} | [
"func",
"(",
"cs",
"Constraints",
")",
"Validate",
"(",
"v",
"*",
"Version",
")",
"(",
"bool",
",",
"[",
"]",
"error",
")",
"{",
"// loop over the ORs and check the inner ANDs",
"var",
"e",
"[",
"]",
"error",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
... | // Validate checks if a version satisfies a constraint. If not a slice of
// reasons for the failure are returned in addition to a bool. | [
"Validate",
"checks",
"if",
"a",
"version",
"satisfies",
"a",
"constraint",
".",
"If",
"not",
"a",
"slice",
"of",
"reasons",
"for",
"the",
"failure",
"are",
"returned",
"in",
"addition",
"to",
"a",
"bool",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L65-L84 |
19,319 | Masterminds/semver | constraints.go | check | func (c *constraint) check(v *Version) bool {
return c.function(v, c)
} | go | func (c *constraint) check(v *Version) bool {
return c.function(v, c)
} | [
"func",
"(",
"c",
"*",
"constraint",
")",
"check",
"(",
"v",
"*",
"Version",
")",
"bool",
"{",
"return",
"c",
".",
"function",
"(",
"v",
",",
"c",
")",
"\n",
"}"
] | // Check if a version meets the constraint | [
"Check",
"if",
"a",
"version",
"meets",
"the",
"constraint"
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/constraints.go#L158-L160 |
19,320 | Masterminds/semver | collection.go | Less | func (c Collection) Less(i, j int) bool {
return c[i].LessThan(c[j])
} | go | func (c Collection) Less(i, j int) bool {
return c[i].LessThan(c[j])
} | [
"func",
"(",
"c",
"Collection",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"c",
"[",
"i",
"]",
".",
"LessThan",
"(",
"c",
"[",
"j",
"]",
")",
"\n",
"}"
] | // Less is needed for the sort interface to compare two Version objects on the
// slice. If checks if one is less than the other. | [
"Less",
"is",
"needed",
"for",
"the",
"sort",
"interface",
"to",
"compare",
"two",
"Version",
"objects",
"on",
"the",
"slice",
".",
"If",
"checks",
"if",
"one",
"is",
"less",
"than",
"the",
"other",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/collection.go#L16-L18 |
19,321 | Masterminds/semver | collection.go | Swap | func (c Collection) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
} | go | func (c Collection) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
} | [
"func",
"(",
"c",
"Collection",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"c",
"[",
"i",
"]",
",",
"c",
"[",
"j",
"]",
"=",
"c",
"[",
"j",
"]",
",",
"c",
"[",
"i",
"]",
"\n",
"}"
] | // Swap is needed for the sort interface to replace the Version objects
// at two different positions in the slice. | [
"Swap",
"is",
"needed",
"for",
"the",
"sort",
"interface",
"to",
"replace",
"the",
"Version",
"objects",
"at",
"two",
"different",
"positions",
"in",
"the",
"slice",
"."
] | 059deebd1619b9ae33232c797f7ab0e8d6c6fd69 | https://github.com/Masterminds/semver/blob/059deebd1619b9ae33232c797f7ab0e8d6c6fd69/collection.go#L22-L24 |
19,322 | mdlayher/netlink | debug.go | newDebugger | func newDebugger(args []string) *debugger {
d := &debugger{
Log: log.New(os.Stderr, "nl: ", 0),
Level: 1,
}
for _, a := range args {
kv := strings.Split(a, "=")
if len(kv) != 2 {
// Ignore malformed pairs and assume callers wants defaults.
continue
}
switch kv[0] {
// Select the log level for the debugger.
case "level":
level, err := strconv.Atoi(kv[1])
if err != nil {
panicf("netlink: invalid NLDEBUG level: %q", a)
}
d.Level = level
}
}
return d
} | go | func newDebugger(args []string) *debugger {
d := &debugger{
Log: log.New(os.Stderr, "nl: ", 0),
Level: 1,
}
for _, a := range args {
kv := strings.Split(a, "=")
if len(kv) != 2 {
// Ignore malformed pairs and assume callers wants defaults.
continue
}
switch kv[0] {
// Select the log level for the debugger.
case "level":
level, err := strconv.Atoi(kv[1])
if err != nil {
panicf("netlink: invalid NLDEBUG level: %q", a)
}
d.Level = level
}
}
return d
} | [
"func",
"newDebugger",
"(",
"args",
"[",
"]",
"string",
")",
"*",
"debugger",
"{",
"d",
":=",
"&",
"debugger",
"{",
"Log",
":",
"log",
".",
"New",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"0",
")",
",",
"Level",
":",
"1",
",",
"}",
"\n... | // newDebugger creates a debugger by parsing key=value arguments. | [
"newDebugger",
"creates",
"a",
"debugger",
"by",
"parsing",
"key",
"=",
"value",
"arguments",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/debug.go#L31-L57 |
19,323 | mdlayher/netlink | debug.go | debugf | func (d *debugger) debugf(level int, format string, v ...interface{}) {
if d.Level >= level {
d.Log.Printf(format, v...)
}
} | go | func (d *debugger) debugf(level int, format string, v ...interface{}) {
if d.Level >= level {
d.Log.Printf(format, v...)
}
} | [
"func",
"(",
"d",
"*",
"debugger",
")",
"debugf",
"(",
"level",
"int",
",",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"d",
".",
"Level",
">=",
"level",
"{",
"d",
".",
"Log",
".",
"Printf",
"(",
"format",
",",
"... | // debugf prints debugging information at the specified level, if d.Level is
// high enough to print the message. | [
"debugf",
"prints",
"debugging",
"information",
"at",
"the",
"specified",
"level",
"if",
"d",
".",
"Level",
"is",
"high",
"enough",
"to",
"print",
"the",
"message",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/debug.go#L61-L65 |
19,324 | mdlayher/netlink | nlenc/int.go | PutUint8 | func PutUint8(b []byte, v uint8) {
if l := len(b); l != 1 {
panic(fmt.Sprintf("PutUint8: unexpected byte slice length: %d", l))
}
b[0] = v
} | go | func PutUint8(b []byte, v uint8) {
if l := len(b); l != 1 {
panic(fmt.Sprintf("PutUint8: unexpected byte slice length: %d", l))
}
b[0] = v
} | [
"func",
"PutUint8",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint8",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"1",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"b"... | // PutUint8 encodes a uint8 into b.
// If b is not exactly 1 byte in length, PutUint8 will panic. | [
"PutUint8",
"encodes",
"a",
"uint8",
"into",
"b",
".",
"If",
"b",
"is",
"not",
"exactly",
"1",
"byte",
"in",
"length",
"PutUint8",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L10-L16 |
19,325 | mdlayher/netlink | nlenc/int.go | PutUint16 | func PutUint16(b []byte, v uint16) {
if l := len(b); l != 2 {
panic(fmt.Sprintf("PutUint16: unexpected byte slice length: %d", l))
}
*(*uint16)(unsafe.Pointer(&b[0])) = v
} | go | func PutUint16(b []byte, v uint16) {
if l := len(b); l != 2 {
panic(fmt.Sprintf("PutUint16: unexpected byte slice length: %d", l))
}
*(*uint16)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutUint16",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint16",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"2",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"... | // PutUint16 encodes a uint16 into b using the host machine's native endianness.
// If b is not exactly 2 bytes in length, PutUint16 will panic. | [
"PutUint16",
"encodes",
"a",
"uint16",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"2",
"bytes",
"in",
"length",
"PutUint16",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L20-L26 |
19,326 | mdlayher/netlink | nlenc/int.go | PutUint32 | func PutUint32(b []byte, v uint32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutUint32: unexpected byte slice length: %d", l))
}
*(*uint32)(unsafe.Pointer(&b[0])) = v
} | go | func PutUint32(b []byte, v uint32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutUint32: unexpected byte slice length: %d", l))
}
*(*uint32)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutUint32",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint32",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"... | // PutUint32 encodes a uint32 into b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, PutUint32 will panic. | [
"PutUint32",
"encodes",
"a",
"uint32",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"PutUint32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L30-L36 |
19,327 | mdlayher/netlink | nlenc/int.go | PutUint64 | func PutUint64(b []byte, v uint64) {
if l := len(b); l != 8 {
panic(fmt.Sprintf("PutUint64: unexpected byte slice length: %d", l))
}
*(*uint64)(unsafe.Pointer(&b[0])) = v
} | go | func PutUint64(b []byte, v uint64) {
if l := len(b); l != 8 {
panic(fmt.Sprintf("PutUint64: unexpected byte slice length: %d", l))
}
*(*uint64)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutUint64",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint64",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"8",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"... | // PutUint64 encodes a uint64 into b using the host machine's native endianness.
// If b is not exactly 8 bytes in length, PutUint64 will panic. | [
"PutUint64",
"encodes",
"a",
"uint64",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"8",
"bytes",
"in",
"length",
"PutUint64",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L40-L46 |
19,328 | mdlayher/netlink | nlenc/int.go | PutInt32 | func PutInt32(b []byte, v int32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutInt32: unexpected byte slice length: %d", l))
}
*(*int32)(unsafe.Pointer(&b[0])) = v
} | go | func PutInt32(b []byte, v int32) {
if l := len(b); l != 4 {
panic(fmt.Sprintf("PutInt32: unexpected byte slice length: %d", l))
}
*(*int32)(unsafe.Pointer(&b[0])) = v
} | [
"func",
"PutInt32",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"int32",
")",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"*"... | // PutInt32 encodes a int32 into b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, PutInt32 will panic. | [
"PutInt32",
"encodes",
"a",
"int32",
"into",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"PutInt32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L50-L56 |
19,329 | mdlayher/netlink | nlenc/int.go | Uint8 | func Uint8(b []byte) uint8 {
if l := len(b); l != 1 {
panic(fmt.Sprintf("Uint8: unexpected byte slice length: %d", l))
}
return b[0]
} | go | func Uint8(b []byte) uint8 {
if l := len(b); l != 1 {
panic(fmt.Sprintf("Uint8: unexpected byte slice length: %d", l))
}
return b[0]
} | [
"func",
"Uint8",
"(",
"b",
"[",
"]",
"byte",
")",
"uint8",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"1",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"b",
"... | // Uint8 decodes a uint8 from b.
// If b is not exactly 1 byte in length, Uint8 will panic. | [
"Uint8",
"decodes",
"a",
"uint8",
"from",
"b",
".",
"If",
"b",
"is",
"not",
"exactly",
"1",
"byte",
"in",
"length",
"Uint8",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L60-L66 |
19,330 | mdlayher/netlink | nlenc/int.go | Uint16 | func Uint16(b []byte) uint16 {
if l := len(b); l != 2 {
panic(fmt.Sprintf("Uint16: unexpected byte slice length: %d", l))
}
return *(*uint16)(unsafe.Pointer(&b[0]))
} | go | func Uint16(b []byte) uint16 {
if l := len(b); l != 2 {
panic(fmt.Sprintf("Uint16: unexpected byte slice length: %d", l))
}
return *(*uint16)(unsafe.Pointer(&b[0]))
} | [
"func",
"Uint16",
"(",
"b",
"[",
"]",
"byte",
")",
"uint16",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"2",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
... | // Uint16 decodes a uint16 from b using the host machine's native endianness.
// If b is not exactly 2 bytes in length, Uint16 will panic. | [
"Uint16",
"decodes",
"a",
"uint16",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"2",
"bytes",
"in",
"length",
"Uint16",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L70-L76 |
19,331 | mdlayher/netlink | nlenc/int.go | Uint32 | func Uint32(b []byte) uint32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Uint32: unexpected byte slice length: %d", l))
}
return *(*uint32)(unsafe.Pointer(&b[0]))
} | go | func Uint32(b []byte) uint32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Uint32: unexpected byte slice length: %d", l))
}
return *(*uint32)(unsafe.Pointer(&b[0]))
} | [
"func",
"Uint32",
"(",
"b",
"[",
"]",
"byte",
")",
"uint32",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
... | // Uint32 decodes a uint32 from b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, Uint32 will panic. | [
"Uint32",
"decodes",
"a",
"uint32",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"Uint32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L80-L86 |
19,332 | mdlayher/netlink | nlenc/int.go | Uint64 | func Uint64(b []byte) uint64 {
if l := len(b); l != 8 {
panic(fmt.Sprintf("Uint64: unexpected byte slice length: %d", l))
}
return *(*uint64)(unsafe.Pointer(&b[0]))
} | go | func Uint64(b []byte) uint64 {
if l := len(b); l != 8 {
panic(fmt.Sprintf("Uint64: unexpected byte slice length: %d", l))
}
return *(*uint64)(unsafe.Pointer(&b[0]))
} | [
"func",
"Uint64",
"(",
"b",
"[",
"]",
"byte",
")",
"uint64",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"8",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
... | // Uint64 decodes a uint64 from b using the host machine's native endianness.
// If b is not exactly 8 bytes in length, Uint64 will panic. | [
"Uint64",
"decodes",
"a",
"uint64",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"8",
"bytes",
"in",
"length",
"Uint64",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L90-L96 |
19,333 | mdlayher/netlink | nlenc/int.go | Int32 | func Int32(b []byte) int32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Int32: unexpected byte slice length: %d", l))
}
return *(*int32)(unsafe.Pointer(&b[0]))
} | go | func Int32(b []byte) int32 {
if l := len(b); l != 4 {
panic(fmt.Sprintf("Int32: unexpected byte slice length: %d", l))
}
return *(*int32)(unsafe.Pointer(&b[0]))
} | [
"func",
"Int32",
"(",
"b",
"[",
"]",
"byte",
")",
"int32",
"{",
"if",
"l",
":=",
"len",
"(",
"b",
")",
";",
"l",
"!=",
"4",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
")",
")",
"\n",
"}",
"\n\n",
"return",
"*",
"... | // Int32 decodes an int32 from b using the host machine's native endianness.
// If b is not exactly 4 bytes in length, Int32 will panic. | [
"Int32",
"decodes",
"an",
"int32",
"from",
"b",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"If",
"b",
"is",
"not",
"exactly",
"4",
"bytes",
"in",
"length",
"Int32",
"will",
"panic",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L100-L106 |
19,334 | mdlayher/netlink | nlenc/int.go | Uint8Bytes | func Uint8Bytes(v uint8) []byte {
b := make([]byte, 1)
PutUint8(b, v)
return b
} | go | func Uint8Bytes(v uint8) []byte {
b := make([]byte, 1)
PutUint8(b, v)
return b
} | [
"func",
"Uint8Bytes",
"(",
"v",
"uint8",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
")",
"\n",
"PutUint8",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint8Bytes encodes a uint8 into a newly-allocated byte slice. It is a
// shortcut for allocating a new byte slice and filling it using PutUint8. | [
"Uint8Bytes",
"encodes",
"a",
"uint8",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"filling",
"it",
"using",
"PutUint8",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L110-L114 |
19,335 | mdlayher/netlink | nlenc/int.go | Uint16Bytes | func Uint16Bytes(v uint16) []byte {
b := make([]byte, 2)
PutUint16(b, v)
return b
} | go | func Uint16Bytes(v uint16) []byte {
b := make([]byte, 2)
PutUint16(b, v)
return b
} | [
"func",
"Uint16Bytes",
"(",
"v",
"uint16",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n",
"PutUint16",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint16Bytes encodes a uint16 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutUint16. | [
"Uint16Bytes",
"encodes",
"a",
"uint16",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fi... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L119-L123 |
19,336 | mdlayher/netlink | nlenc/int.go | Uint32Bytes | func Uint32Bytes(v uint32) []byte {
b := make([]byte, 4)
PutUint32(b, v)
return b
} | go | func Uint32Bytes(v uint32) []byte {
b := make([]byte, 4)
PutUint32(b, v)
return b
} | [
"func",
"Uint32Bytes",
"(",
"v",
"uint32",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"PutUint32",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint32Bytes encodes a uint32 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutUint32. | [
"Uint32Bytes",
"encodes",
"a",
"uint32",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fi... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L128-L132 |
19,337 | mdlayher/netlink | nlenc/int.go | Uint64Bytes | func Uint64Bytes(v uint64) []byte {
b := make([]byte, 8)
PutUint64(b, v)
return b
} | go | func Uint64Bytes(v uint64) []byte {
b := make([]byte, 8)
PutUint64(b, v)
return b
} | [
"func",
"Uint64Bytes",
"(",
"v",
"uint64",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",
"PutUint64",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Uint64Bytes encodes a uint64 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutUint64. | [
"Uint64Bytes",
"encodes",
"a",
"uint64",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fi... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L137-L141 |
19,338 | mdlayher/netlink | nlenc/int.go | Int32Bytes | func Int32Bytes(v int32) []byte {
b := make([]byte, 4)
PutInt32(b, v)
return b
} | go | func Int32Bytes(v int32) []byte {
b := make([]byte, 4)
PutInt32(b, v)
return b
} | [
"func",
"Int32Bytes",
"(",
"v",
"int32",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"PutInt32",
"(",
"b",
",",
"v",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Int32Bytes encodes a int32 into a newly-allocated byte slice using the
// host machine's native endianness. It is a shortcut for allocating a new
// byte slice and filling it using PutInt32. | [
"Int32Bytes",
"encodes",
"a",
"int32",
"into",
"a",
"newly",
"-",
"allocated",
"byte",
"slice",
"using",
"the",
"host",
"machine",
"s",
"native",
"endianness",
".",
"It",
"is",
"a",
"shortcut",
"for",
"allocating",
"a",
"new",
"byte",
"slice",
"and",
"fill... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/int.go#L146-L150 |
19,339 | mdlayher/netlink | nlenc/endian.go | NativeEndian | func NativeEndian() binary.ByteOrder {
// Determine endianness by storing a uint16 in a byte slice.
b := Uint16Bytes(1)
if b[0] == 1 {
return binary.LittleEndian
}
return binary.BigEndian
} | go | func NativeEndian() binary.ByteOrder {
// Determine endianness by storing a uint16 in a byte slice.
b := Uint16Bytes(1)
if b[0] == 1 {
return binary.LittleEndian
}
return binary.BigEndian
} | [
"func",
"NativeEndian",
"(",
")",
"binary",
".",
"ByteOrder",
"{",
"// Determine endianness by storing a uint16 in a byte slice.",
"b",
":=",
"Uint16Bytes",
"(",
"1",
")",
"\n",
"if",
"b",
"[",
"0",
"]",
"==",
"1",
"{",
"return",
"binary",
".",
"LittleEndian",
... | // NativeEndian returns the native byte order of this system. | [
"NativeEndian",
"returns",
"the",
"native",
"byte",
"order",
"of",
"this",
"system",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/nlenc/endian.go#L6-L14 |
19,340 | mdlayher/netlink | message.go | String | func (f HeaderFlags) String() string {
names := []string{
"request",
"multi",
"acknowledge",
"echo",
"dumpinterrupted",
"dumpfiltered",
}
var s string
left := uint(f)
for i, name := range names {
if f&(1<<uint(i)) != 0 {
if s != "" {
s += "|"
}
s += name
left ^= (1 << uint(i))
}
}
if s == "" && left == 0 {
s = "0"
}
if left > 0 {
if s != "" {
s += "|"
}
s += fmt.Sprintf("%#x", left)
}
return s
} | go | func (f HeaderFlags) String() string {
names := []string{
"request",
"multi",
"acknowledge",
"echo",
"dumpinterrupted",
"dumpfiltered",
}
var s string
left := uint(f)
for i, name := range names {
if f&(1<<uint(i)) != 0 {
if s != "" {
s += "|"
}
s += name
left ^= (1 << uint(i))
}
}
if s == "" && left == 0 {
s = "0"
}
if left > 0 {
if s != "" {
s += "|"
}
s += fmt.Sprintf("%#x", left)
}
return s
} | [
"func",
"(",
"f",
"HeaderFlags",
")",
"String",
"(",
")",
"string",
"{",
"names",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"}",
"\n\n",
"var",
"s",
... | // String returns the string representation of a HeaderFlags. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"HeaderFlags",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L77-L115 |
19,341 | mdlayher/netlink | message.go | String | func (t HeaderType) String() string {
switch t {
case Noop:
return "noop"
case Error:
return "error"
case Done:
return "done"
case Overrun:
return "overrun"
default:
return fmt.Sprintf("unknown(%d)", t)
}
} | go | func (t HeaderType) String() string {
switch t {
case Noop:
return "noop"
case Error:
return "error"
case Done:
return "done"
case Overrun:
return "overrun"
default:
return fmt.Sprintf("unknown(%d)", t)
}
} | [
"func",
"(",
"t",
"HeaderType",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"Noop",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Error",
":",
"return",
"\"",
"\"",
"\n",
"case",
"Done",
":",
"return",
"\"",
"\"",
"\n",
"case",
... | // String returns the string representation of a HeaderType. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"HeaderType",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L136-L149 |
19,342 | mdlayher/netlink | message.go | MarshalBinary | func (m Message) MarshalBinary() ([]byte, error) {
ml := nlmsgAlign(int(m.Header.Length))
if ml < nlmsgHeaderLen || ml != int(m.Header.Length) {
return nil, errIncorrectMessageLength
}
b := make([]byte, ml)
nlenc.PutUint32(b[0:4], m.Header.Length)
nlenc.PutUint16(b[4:6], uint16(m.Header.Type))
nlenc.PutUint16(b[6:8], uint16(m.Header.Flags))
nlenc.PutUint32(b[8:12], m.Header.Sequence)
nlenc.PutUint32(b[12:16], m.Header.PID)
copy(b[16:], m.Data)
return b, nil
} | go | func (m Message) MarshalBinary() ([]byte, error) {
ml := nlmsgAlign(int(m.Header.Length))
if ml < nlmsgHeaderLen || ml != int(m.Header.Length) {
return nil, errIncorrectMessageLength
}
b := make([]byte, ml)
nlenc.PutUint32(b[0:4], m.Header.Length)
nlenc.PutUint16(b[4:6], uint16(m.Header.Type))
nlenc.PutUint16(b[6:8], uint16(m.Header.Flags))
nlenc.PutUint32(b[8:12], m.Header.Sequence)
nlenc.PutUint32(b[12:16], m.Header.PID)
copy(b[16:], m.Data)
return b, nil
} | [
"func",
"(",
"m",
"Message",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ml",
":=",
"nlmsgAlign",
"(",
"int",
"(",
"m",
".",
"Header",
".",
"Length",
")",
")",
"\n",
"if",
"ml",
"<",
"nlmsgHeaderLen",
"||",
"ml... | // MarshalBinary marshals a Message into a byte slice. | [
"MarshalBinary",
"marshals",
"a",
"Message",
"into",
"a",
"byte",
"slice",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L185-L201 |
19,343 | mdlayher/netlink | message.go | UnmarshalBinary | func (m *Message) UnmarshalBinary(b []byte) error {
if len(b) < nlmsgHeaderLen {
return errShortMessage
}
if len(b) != nlmsgAlign(len(b)) {
return errUnalignedMessage
}
// Don't allow misleading length
m.Header.Length = nlenc.Uint32(b[0:4])
if int(m.Header.Length) != len(b) {
return errShortMessage
}
m.Header.Type = HeaderType(nlenc.Uint16(b[4:6]))
m.Header.Flags = HeaderFlags(nlenc.Uint16(b[6:8]))
m.Header.Sequence = nlenc.Uint32(b[8:12])
m.Header.PID = nlenc.Uint32(b[12:16])
m.Data = b[16:]
return nil
} | go | func (m *Message) UnmarshalBinary(b []byte) error {
if len(b) < nlmsgHeaderLen {
return errShortMessage
}
if len(b) != nlmsgAlign(len(b)) {
return errUnalignedMessage
}
// Don't allow misleading length
m.Header.Length = nlenc.Uint32(b[0:4])
if int(m.Header.Length) != len(b) {
return errShortMessage
}
m.Header.Type = HeaderType(nlenc.Uint16(b[4:6]))
m.Header.Flags = HeaderFlags(nlenc.Uint16(b[6:8]))
m.Header.Sequence = nlenc.Uint32(b[8:12])
m.Header.PID = nlenc.Uint32(b[12:16])
m.Data = b[16:]
return nil
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"UnmarshalBinary",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"nlmsgHeaderLen",
"{",
"return",
"errShortMessage",
"\n",
"}",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"nlmsgA... | // UnmarshalBinary unmarshals the contents of a byte slice into a Message. | [
"UnmarshalBinary",
"unmarshals",
"the",
"contents",
"of",
"a",
"byte",
"slice",
"into",
"a",
"Message",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L204-L225 |
19,344 | mdlayher/netlink | message.go | checkMessage | func checkMessage(m Message) error {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
const success = 0
// Per libnl documentation, only messages that indicate type error can
// contain error codes:
// https://www.infradead.org/~tgr/libnl/doc/core.html#core_errmsg.
//
// However, at one point, this package checked both done and error for
// error codes. Because there was no issue associated with the change,
// it is unknown whether this change was correct or not. If you run into
// a problem with your application because of this change, please file
// an issue.
if m.Header.Type != Error {
return nil
}
if len(m.Data) < 4 {
return newOpError("receive", errShortErrorMessage)
}
if c := nlenc.Int32(m.Data[0:4]); c != success {
// Error code is a negative integer, convert it into an OS-specific raw
// system call error, but do not wrap with os.NewSyscallError to signify
// that this error was produced by a netlink message; not a system call.
return newOpError("receive", newError(-1*int(c)))
}
return nil
} | go | func checkMessage(m Message) error {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
const success = 0
// Per libnl documentation, only messages that indicate type error can
// contain error codes:
// https://www.infradead.org/~tgr/libnl/doc/core.html#core_errmsg.
//
// However, at one point, this package checked both done and error for
// error codes. Because there was no issue associated with the change,
// it is unknown whether this change was correct or not. If you run into
// a problem with your application because of this change, please file
// an issue.
if m.Header.Type != Error {
return nil
}
if len(m.Data) < 4 {
return newOpError("receive", errShortErrorMessage)
}
if c := nlenc.Int32(m.Data[0:4]); c != success {
// Error code is a negative integer, convert it into an OS-specific raw
// system call error, but do not wrap with os.NewSyscallError to signify
// that this error was produced by a netlink message; not a system call.
return newOpError("receive", newError(-1*int(c)))
}
return nil
} | [
"func",
"checkMessage",
"(",
"m",
"Message",
")",
"error",
"{",
"// NB: All non-nil errors returned from this function *must* be of type",
"// OpError in order to maintain the appropriate contract with callers of",
"// this package.",
"const",
"success",
"=",
"0",
"\n\n",
"// Per lib... | // checkMessage checks a single Message for netlink errors. | [
"checkMessage",
"checks",
"a",
"single",
"Message",
"for",
"netlink",
"errors",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/message.go#L228-L260 |
19,345 | mdlayher/netlink | attribute.go | marshal | func (a *Attribute) marshal(b []byte) (int, error) {
if int(a.Length) < nlaHeaderLen {
return 0, errInvalidAttribute
}
nlenc.PutUint16(b[0:2], a.Length)
nlenc.PutUint16(b[2:4], a.Type)
n := copy(b[nlaHeaderLen:], a.Data)
return nlaHeaderLen + nlaAlign(n), nil
} | go | func (a *Attribute) marshal(b []byte) (int, error) {
if int(a.Length) < nlaHeaderLen {
return 0, errInvalidAttribute
}
nlenc.PutUint16(b[0:2], a.Length)
nlenc.PutUint16(b[2:4], a.Type)
n := copy(b[nlaHeaderLen:], a.Data)
return nlaHeaderLen + nlaAlign(n), nil
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"marshal",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"int",
"(",
"a",
".",
"Length",
")",
"<",
"nlaHeaderLen",
"{",
"return",
"0",
",",
"errInvalidAttribute",
"\n",
"}",
"\... | // marshal marshals the contents of a into b and returns the number of bytes
// written to b, including attribute alignment padding. | [
"marshal",
"marshals",
"the",
"contents",
"of",
"a",
"into",
"b",
"and",
"returns",
"the",
"number",
"of",
"bytes",
"written",
"to",
"b",
"including",
"attribute",
"alignment",
"padding",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L29-L39 |
19,346 | mdlayher/netlink | attribute.go | unmarshal | func (a *Attribute) unmarshal(b []byte) error {
if len(b) < nlaHeaderLen {
return errInvalidAttribute
}
a.Length = nlenc.Uint16(b[0:2])
a.Type = nlenc.Uint16(b[2:4])
if int(a.Length) > len(b) {
return errInvalidAttribute
}
switch {
// No length, no data
case a.Length == 0:
a.Data = make([]byte, 0)
// Not enough length for any data
case int(a.Length) < nlaHeaderLen:
return errInvalidAttribute
// Data present
case int(a.Length) >= nlaHeaderLen:
a.Data = make([]byte, len(b[nlaHeaderLen:a.Length]))
copy(a.Data, b[nlaHeaderLen:a.Length])
}
return nil
} | go | func (a *Attribute) unmarshal(b []byte) error {
if len(b) < nlaHeaderLen {
return errInvalidAttribute
}
a.Length = nlenc.Uint16(b[0:2])
a.Type = nlenc.Uint16(b[2:4])
if int(a.Length) > len(b) {
return errInvalidAttribute
}
switch {
// No length, no data
case a.Length == 0:
a.Data = make([]byte, 0)
// Not enough length for any data
case int(a.Length) < nlaHeaderLen:
return errInvalidAttribute
// Data present
case int(a.Length) >= nlaHeaderLen:
a.Data = make([]byte, len(b[nlaHeaderLen:a.Length]))
copy(a.Data, b[nlaHeaderLen:a.Length])
}
return nil
} | [
"func",
"(",
"a",
"*",
"Attribute",
")",
"unmarshal",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"nlaHeaderLen",
"{",
"return",
"errInvalidAttribute",
"\n",
"}",
"\n\n",
"a",
".",
"Length",
"=",
"nlenc",
".",
"U... | // unmarshal unmarshals the contents of a byte slice into an Attribute. | [
"unmarshal",
"unmarshals",
"the",
"contents",
"of",
"a",
"byte",
"slice",
"into",
"an",
"Attribute",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L42-L68 |
19,347 | mdlayher/netlink | attribute.go | MarshalAttributes | func MarshalAttributes(attrs []Attribute) ([]byte, error) {
// Count how many bytes we should allocate to store each attribute's contents.
var c int
for _, a := range attrs {
c += nlaHeaderLen + nlaAlign(len(a.Data))
}
// Advance through b with idx to place attribute data at the correct offset.
var idx int
b := make([]byte, c)
for _, a := range attrs {
// Infer the length of attribute if zero.
if a.Length == 0 {
a.Length = uint16(nlaHeaderLen + len(a.Data))
}
// Marshal a into b and advance idx to show many bytes are occupied.
n, err := a.marshal(b[idx:])
if err != nil {
return nil, err
}
idx += n
}
return b, nil
} | go | func MarshalAttributes(attrs []Attribute) ([]byte, error) {
// Count how many bytes we should allocate to store each attribute's contents.
var c int
for _, a := range attrs {
c += nlaHeaderLen + nlaAlign(len(a.Data))
}
// Advance through b with idx to place attribute data at the correct offset.
var idx int
b := make([]byte, c)
for _, a := range attrs {
// Infer the length of attribute if zero.
if a.Length == 0 {
a.Length = uint16(nlaHeaderLen + len(a.Data))
}
// Marshal a into b and advance idx to show many bytes are occupied.
n, err := a.marshal(b[idx:])
if err != nil {
return nil, err
}
idx += n
}
return b, nil
} | [
"func",
"MarshalAttributes",
"(",
"attrs",
"[",
"]",
"Attribute",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Count how many bytes we should allocate to store each attribute's contents.",
"var",
"c",
"int",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
... | // MarshalAttributes packs a slice of Attributes into a single byte slice.
// In most cases, the Length field of each Attribute should be set to 0, so it
// can be calculated and populated automatically for each Attribute. | [
"MarshalAttributes",
"packs",
"a",
"slice",
"of",
"Attributes",
"into",
"a",
"single",
"byte",
"slice",
".",
"In",
"most",
"cases",
"the",
"Length",
"field",
"of",
"each",
"Attribute",
"should",
"be",
"set",
"to",
"0",
"so",
"it",
"can",
"be",
"calculated"... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L73-L98 |
19,348 | mdlayher/netlink | attribute.go | UnmarshalAttributes | func UnmarshalAttributes(b []byte) ([]Attribute, error) {
var attrs []Attribute
var i int
for {
if i > len(b) || len(b[i:]) == 0 {
break
}
var a Attribute
if err := (&a).unmarshal(b[i:]); err != nil {
return nil, err
}
if a.Length == 0 {
i += nlaHeaderLen
continue
}
i += nlaAlign(int(a.Length))
attrs = append(attrs, a)
}
return attrs, nil
} | go | func UnmarshalAttributes(b []byte) ([]Attribute, error) {
var attrs []Attribute
var i int
for {
if i > len(b) || len(b[i:]) == 0 {
break
}
var a Attribute
if err := (&a).unmarshal(b[i:]); err != nil {
return nil, err
}
if a.Length == 0 {
i += nlaHeaderLen
continue
}
i += nlaAlign(int(a.Length))
attrs = append(attrs, a)
}
return attrs, nil
} | [
"func",
"UnmarshalAttributes",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"Attribute",
",",
"error",
")",
"{",
"var",
"attrs",
"[",
"]",
"Attribute",
"\n",
"var",
"i",
"int",
"\n",
"for",
"{",
"if",
"i",
">",
"len",
"(",
"b",
")",
"||",
"l... | // UnmarshalAttributes unpacks a slice of Attributes from a single byte slice.
//
// It is recommend to use the AttributeDecoder type where possible instead of calling
// UnmarshalAttributes and using package nlenc functions directly. | [
"UnmarshalAttributes",
"unpacks",
"a",
"slice",
"of",
"Attributes",
"from",
"a",
"single",
"byte",
"slice",
".",
"It",
"is",
"recommend",
"to",
"use",
"the",
"AttributeDecoder",
"type",
"where",
"possible",
"instead",
"of",
"calling",
"UnmarshalAttributes",
"and",... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L104-L128 |
19,349 | mdlayher/netlink | attribute.go | NewAttributeDecoder | func NewAttributeDecoder(b []byte) (*AttributeDecoder, error) {
attrs, err := UnmarshalAttributes(b)
if err != nil {
return nil, err
}
return &AttributeDecoder{
// By default, use native byte order.
ByteOrder: nlenc.NativeEndian(),
attrs: attrs,
}, nil
} | go | func NewAttributeDecoder(b []byte) (*AttributeDecoder, error) {
attrs, err := UnmarshalAttributes(b)
if err != nil {
return nil, err
}
return &AttributeDecoder{
// By default, use native byte order.
ByteOrder: nlenc.NativeEndian(),
attrs: attrs,
}, nil
} | [
"func",
"NewAttributeDecoder",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"*",
"AttributeDecoder",
",",
"error",
")",
"{",
"attrs",
",",
"err",
":=",
"UnmarshalAttributes",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"... | // NewAttributeDecoder creates an AttributeDecoder that unpacks Attributes
// from b and prepares the decoder for iteration. | [
"NewAttributeDecoder",
"creates",
"an",
"AttributeDecoder",
"that",
"unpacks",
"Attributes",
"from",
"b",
"and",
"prepares",
"the",
"decoder",
"for",
"iteration",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L157-L169 |
19,350 | mdlayher/netlink | attribute.go | Next | func (ad *AttributeDecoder) Next() bool {
if ad.err != nil {
// Hit an error, stop iteration.
return false
}
ad.i++
// More attributes?
return len(ad.attrs) >= ad.i
} | go | func (ad *AttributeDecoder) Next() bool {
if ad.err != nil {
// Hit an error, stop iteration.
return false
}
ad.i++
// More attributes?
return len(ad.attrs) >= ad.i
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"// Hit an error, stop iteration.",
"return",
"false",
"\n",
"}",
"\n\n",
"ad",
".",
"i",
"++",
"\n\n",
"// More attributes?",
"return... | // Next advances the decoder to the next netlink attribute. It returns false
// when no more attributes are present, or an error was encountered. | [
"Next",
"advances",
"the",
"decoder",
"to",
"the",
"next",
"netlink",
"attribute",
".",
"It",
"returns",
"false",
"when",
"no",
"more",
"attributes",
"are",
"present",
"or",
"an",
"error",
"was",
"encountered",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L173-L183 |
19,351 | mdlayher/netlink | attribute.go | Bytes | func (ad *AttributeDecoder) Bytes() []byte {
src := ad.data()
dest := make([]byte, len(src))
copy(dest, src)
return dest
} | go | func (ad *AttributeDecoder) Bytes() []byte {
src := ad.data()
dest := make([]byte, len(src))
copy(dest, src)
return dest
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"src",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"dest",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"src",
")",
")",
"\n",
"copy",
"(",
"dest... | // Bytes returns the raw bytes of the current Attribute's data. | [
"Bytes",
"returns",
"the",
"raw",
"bytes",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L207-L212 |
19,352 | mdlayher/netlink | attribute.go | String | func (ad *AttributeDecoder) String() string {
if ad.err != nil {
return ""
}
return nlenc.String(ad.data())
} | go | func (ad *AttributeDecoder) String() string {
if ad.err != nil {
return ""
}
return nlenc.String(ad.data())
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"String",
"(",
")",
"string",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"nlenc",
".",
"String",
"(",
"ad",
".",
"data",
"(",
")",
")",
"\n",
... | // String returns the string representation of the current Attribute's data. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L215-L221 |
19,353 | mdlayher/netlink | attribute.go | Uint8 | func (ad *AttributeDecoder) Uint8() uint8 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 1 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint8; length: %d", ad.Type(), len(b))
return 0
}
return uint8(b[0])
} | go | func (ad *AttributeDecoder) Uint8() uint8 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 1 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint8; length: %d", ad.Type(), len(b))
return 0
}
return uint8(b[0])
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint8",
"(",
")",
"uint8",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"1",... | // Uint8 returns the uint8 representation of the current Attribute's data. | [
"Uint8",
"returns",
"the",
"uint8",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L224-L236 |
19,354 | mdlayher/netlink | attribute.go | Uint16 | func (ad *AttributeDecoder) Uint16() uint16 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 2 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint16; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint16(b)
} | go | func (ad *AttributeDecoder) Uint16() uint16 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 2 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint16; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint16(b)
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint16",
"(",
")",
"uint16",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"2... | // Uint16 returns the uint16 representation of the current Attribute's data. | [
"Uint16",
"returns",
"the",
"uint16",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L239-L251 |
19,355 | mdlayher/netlink | attribute.go | Uint32 | func (ad *AttributeDecoder) Uint32() uint32 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 4 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint32; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint32(b)
} | go | func (ad *AttributeDecoder) Uint32() uint32 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 4 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint32; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint32(b)
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint32",
"(",
")",
"uint32",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"4... | // Uint32 returns the uint32 representation of the current Attribute's data. | [
"Uint32",
"returns",
"the",
"uint32",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L254-L266 |
19,356 | mdlayher/netlink | attribute.go | Uint64 | func (ad *AttributeDecoder) Uint64() uint64 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 8 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint64; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint64(b)
} | go | func (ad *AttributeDecoder) Uint64() uint64 {
if ad.err != nil {
return 0
}
b := ad.data()
if len(b) != 8 {
ad.err = fmt.Errorf("netlink: attribute %d is not a uint64; length: %d", ad.Type(), len(b))
return 0
}
return ad.ByteOrder.Uint64(b)
} | [
"func",
"(",
"ad",
"*",
"AttributeDecoder",
")",
"Uint64",
"(",
")",
"uint64",
"{",
"if",
"ad",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"b",
":=",
"ad",
".",
"data",
"(",
")",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"8... | // Uint64 returns the uint64 representation of the current Attribute's data. | [
"Uint64",
"returns",
"the",
"uint64",
"representation",
"of",
"the",
"current",
"Attribute",
"s",
"data",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L269-L281 |
19,357 | mdlayher/netlink | attribute.go | Uint8 | func (ae *AttributeEncoder) Uint8(typ uint16, v uint8) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: []byte{v},
})
} | go | func (ae *AttributeEncoder) Uint8(typ uint16, v uint8) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: []byte{v},
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint8",
"(",
"typ",
"uint16",
",",
"v",
"uint8",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ae",
".",
"attrs",
"=",
"append",
"(",
"ae",
".",
"attrs",
",",
... | // Uint8 encodes uint8 data into an Attribute specified by typ. | [
"Uint8",
"encodes",
"uint8",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L331-L340 |
19,358 | mdlayher/netlink | attribute.go | Uint16 | func (ae *AttributeEncoder) Uint16(typ uint16, v uint16) {
if ae.err != nil {
return
}
b := make([]byte, 2)
ae.ByteOrder.PutUint16(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Uint16(typ uint16, v uint16) {
if ae.err != nil {
return
}
b := make([]byte, 2)
ae.ByteOrder.PutUint16(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint16",
"(",
"typ",
"uint16",
",",
"v",
"uint16",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n",... | // Uint16 encodes uint16 data into an Attribute specified by typ. | [
"Uint16",
"encodes",
"uint16",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L343-L355 |
19,359 | mdlayher/netlink | attribute.go | Uint32 | func (ae *AttributeEncoder) Uint32(typ uint16, v uint32) {
if ae.err != nil {
return
}
b := make([]byte, 4)
ae.ByteOrder.PutUint32(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Uint32(typ uint16, v uint32) {
if ae.err != nil {
return
}
b := make([]byte, 4)
ae.ByteOrder.PutUint32(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint32",
"(",
"typ",
"uint16",
",",
"v",
"uint32",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",... | // Uint32 encodes uint32 data into an Attribute specified by typ. | [
"Uint32",
"encodes",
"uint32",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L358-L370 |
19,360 | mdlayher/netlink | attribute.go | Uint64 | func (ae *AttributeEncoder) Uint64(typ uint16, v uint64) {
if ae.err != nil {
return
}
b := make([]byte, 8)
ae.ByteOrder.PutUint64(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Uint64(typ uint16, v uint64) {
if ae.err != nil {
return
}
b := make([]byte, 8)
ae.ByteOrder.PutUint64(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint64",
"(",
"typ",
"uint16",
",",
"v",
"uint64",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",... | // Uint64 encodes uint64 data into an Attribute specified by typ. | [
"Uint64",
"encodes",
"uint64",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L373-L385 |
19,361 | mdlayher/netlink | attribute.go | String | func (ae *AttributeEncoder) String(typ uint16, s string) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: nlenc.Bytes(s),
})
} | go | func (ae *AttributeEncoder) String(typ uint16, s string) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: nlenc.Bytes(s),
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"String",
"(",
"typ",
"uint16",
",",
"s",
"string",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ae",
".",
"attrs",
"=",
"append",
"(",
"ae",
".",
"attrs",
",",... | // String encodes string s as a null-terminated string into an Attribute
// specified by typ. | [
"String",
"encodes",
"string",
"s",
"as",
"a",
"null",
"-",
"terminated",
"string",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L389-L398 |
19,362 | mdlayher/netlink | attribute.go | Bytes | func (ae *AttributeEncoder) Bytes(typ uint16, b []byte) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Bytes(typ uint16, b []byte) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Bytes",
"(",
"typ",
"uint16",
",",
"b",
"[",
"]",
"byte",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ae",
".",
"attrs",
"=",
"append",
"(",
"ae",
".",
"att... | // Bytes embeds raw byte data into an Attribute specified by typ. | [
"Bytes",
"embeds",
"raw",
"byte",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L401-L410 |
19,363 | mdlayher/netlink | attribute.go | Encode | func (ae *AttributeEncoder) Encode() ([]byte, error) {
if ae.err != nil {
return nil, ae.err
}
return MarshalAttributes(ae.attrs)
} | go | func (ae *AttributeEncoder) Encode() ([]byte, error) {
if ae.err != nil {
return nil, ae.err
}
return MarshalAttributes(ae.attrs)
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Encode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"ae",
".",
"err",
"\n",
"}",
"\n\n",
"return",
"MarshalAttributes",
... | // Encode returns the encoded bytes representing the attributes. | [
"Encode",
"returns",
"the",
"encoded",
"bytes",
"representing",
"the",
"attributes",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L436-L442 |
19,364 | mdlayher/netlink | conn.go | Dial | func Dial(family int, config *Config) (*Conn, error) {
// Use OS-specific dial() to create Socket
c, pid, err := dial(family, config)
if err != nil {
return nil, err
}
return NewConn(c, pid), nil
} | go | func Dial(family int, config *Config) (*Conn, error) {
// Use OS-specific dial() to create Socket
c, pid, err := dial(family, config)
if err != nil {
return nil, err
}
return NewConn(c, pid), nil
} | [
"func",
"Dial",
"(",
"family",
"int",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"// Use OS-specific dial() to create Socket",
"c",
",",
"pid",
",",
"err",
":=",
"dial",
"(",
"family",
",",
"config",
")",
"\n",
"if",
"... | // Dial dials a connection to netlink, using the specified netlink family.
// Config specifies optional configuration for Conn. If config is nil, a default
// configuration will be used. | [
"Dial",
"dials",
"a",
"connection",
"to",
"netlink",
"using",
"the",
"specified",
"netlink",
"family",
".",
"Config",
"specifies",
"optional",
"configuration",
"for",
"Conn",
".",
"If",
"config",
"is",
"nil",
"a",
"default",
"configuration",
"will",
"be",
"use... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L53-L61 |
19,365 | mdlayher/netlink | conn.go | NewConn | func NewConn(sock Socket, pid uint32) *Conn {
// Seed the sequence number using a random number generator.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seq := r.Uint32()
// Configure a debugger if arguments are set.
var d *debugger
if len(debugArgs) > 0 {
d = newDebugger(debugArgs)
}
return &Conn{
sock: sock,
seq: &seq,
pid: pid,
d: d,
}
} | go | func NewConn(sock Socket, pid uint32) *Conn {
// Seed the sequence number using a random number generator.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seq := r.Uint32()
// Configure a debugger if arguments are set.
var d *debugger
if len(debugArgs) > 0 {
d = newDebugger(debugArgs)
}
return &Conn{
sock: sock,
seq: &seq,
pid: pid,
d: d,
}
} | [
"func",
"NewConn",
"(",
"sock",
"Socket",
",",
"pid",
"uint32",
")",
"*",
"Conn",
"{",
"// Seed the sequence number using a random number generator.",
"r",
":=",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix... | // NewConn creates a Conn using the specified Socket and PID for netlink
// communications.
//
// NewConn is primarily useful for tests. Most applications should use
// Dial instead. | [
"NewConn",
"creates",
"a",
"Conn",
"using",
"the",
"specified",
"Socket",
"and",
"PID",
"for",
"netlink",
"communications",
".",
"NewConn",
"is",
"primarily",
"useful",
"for",
"tests",
".",
"Most",
"applications",
"should",
"use",
"Dial",
"instead",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L68-L85 |
19,366 | mdlayher/netlink | conn.go | debug | func (c *Conn) debug(fn func(d *debugger)) {
if c.d == nil {
return
}
fn(c.d)
} | go | func (c *Conn) debug(fn func(d *debugger)) {
if c.d == nil {
return
}
fn(c.d)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"debug",
"(",
"fn",
"func",
"(",
"d",
"*",
"debugger",
")",
")",
"{",
"if",
"c",
".",
"d",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"fn",
"(",
"c",
".",
"d",
")",
"\n",
"}"
] | // debug executes fn with the debugger if the debugger is not nil. | [
"debug",
"executes",
"fn",
"with",
"the",
"debugger",
"if",
"the",
"debugger",
"is",
"not",
"nil",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L88-L94 |
19,367 | mdlayher/netlink | conn.go | SendMessages | func (c *Conn) SendMessages(messages []Message) ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
for idx, m := range messages {
ml := nlmsgLength(len(m.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
return nil, errors.New("netlink message data too large")
}
c.fixMsg(&messages[idx], ml)
}
c.debug(func(d *debugger) {
for _, m := range messages {
d.debugf(1, "send msgs: %+v", m)
}
})
if err := c.sock.SendMessages(messages); err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "send msgs: err: %v", err)
})
return nil, newOpError("send-messages", err)
}
return messages, nil
} | go | func (c *Conn) SendMessages(messages []Message) ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
for idx, m := range messages {
ml := nlmsgLength(len(m.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
return nil, errors.New("netlink message data too large")
}
c.fixMsg(&messages[idx], ml)
}
c.debug(func(d *debugger) {
for _, m := range messages {
d.debugf(1, "send msgs: %+v", m)
}
})
if err := c.sock.SendMessages(messages); err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "send msgs: err: %v", err)
})
return nil, newOpError("send-messages", err)
}
return messages, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SendMessages",
"(",
"messages",
"[",
"]",
"Message",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"// Wait for any concurrent calls to Execute to finish before proceeding.",
"c",
".",
"mu",
".",
"RLock",
"(",
")",... | // SendMessages sends multiple Messages to netlink. The handling of
// a Header's Length, Sequence and PID fields is the same as when
// calling Send. | [
"SendMessages",
"sends",
"multiple",
"Messages",
"to",
"netlink",
".",
"The",
"handling",
"of",
"a",
"Header",
"s",
"Length",
"Sequence",
"and",
"PID",
"fields",
"is",
"the",
"same",
"as",
"when",
"calling",
"Send",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L144-L175 |
19,368 | mdlayher/netlink | conn.go | Send | func (c *Conn) Send(message Message) (Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedSend(message)
} | go | func (c *Conn) Send(message Message) (Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedSend(message)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Send",
"(",
"message",
"Message",
")",
"(",
"Message",
",",
"error",
")",
"{",
"// Wait for any concurrent calls to Execute to finish before proceeding.",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"... | // Send sends a single Message to netlink. In most cases, a Header's Length,
// Sequence, and PID fields should be set to 0, so they can be populated
// automatically before the Message is sent. On success, Send returns a copy
// of the Message with all parameters populated, for later validation.
//
// If Header.Length is 0, it will be automatically populated using the
// correct length for the Message, including its payload.
//
// If Header.Sequence is 0, it will be automatically populated using the
// next sequence number for this connection.
//
// If Header.PID is 0, it will be automatically populated using a PID
// assigned by netlink. | [
"Send",
"sends",
"a",
"single",
"Message",
"to",
"netlink",
".",
"In",
"most",
"cases",
"a",
"Header",
"s",
"Length",
"Sequence",
"and",
"PID",
"fields",
"should",
"be",
"set",
"to",
"0",
"so",
"they",
"can",
"be",
"populated",
"automatically",
"before",
... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L190-L196 |
19,369 | mdlayher/netlink | conn.go | lockedSend | func (c *Conn) lockedSend(message Message) (Message, error) {
ml := nlmsgLength(len(message.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
return Message{}, errors.New("netlink message data too large")
}
c.fixMsg(&message, ml)
c.debug(func(d *debugger) {
d.debugf(1, "send: %+v", message)
})
if err := c.sock.Send(message); err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "send: err: %v", err)
})
return Message{}, newOpError("send", err)
}
return message, nil
} | go | func (c *Conn) lockedSend(message Message) (Message, error) {
ml := nlmsgLength(len(message.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
return Message{}, errors.New("netlink message data too large")
}
c.fixMsg(&message, ml)
c.debug(func(d *debugger) {
d.debugf(1, "send: %+v", message)
})
if err := c.sock.Send(message); err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "send: err: %v", err)
})
return Message{}, newOpError("send", err)
}
return message, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"lockedSend",
"(",
"message",
"Message",
")",
"(",
"Message",
",",
"error",
")",
"{",
"ml",
":=",
"nlmsgLength",
"(",
"len",
"(",
"message",
".",
"Data",
")",
")",
"\n\n",
"// TODO(mdlayher): fine-tune this limit.",
"if"... | // lockedSend implements Send, but must be called with c.mu acquired for reading.
// We rely on the kernel to deal with concurrent reads and writes to the netlink
// socket itself. | [
"lockedSend",
"implements",
"Send",
"but",
"must",
"be",
"called",
"with",
"c",
".",
"mu",
"acquired",
"for",
"reading",
".",
"We",
"rely",
"on",
"the",
"kernel",
"to",
"deal",
"with",
"concurrent",
"reads",
"and",
"writes",
"to",
"the",
"netlink",
"socket... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L201-L224 |
19,370 | mdlayher/netlink | conn.go | Receive | func (c *Conn) Receive() ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedReceive()
} | go | func (c *Conn) Receive() ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedReceive()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Receive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"// Wait for any concurrent calls to Execute to finish before proceeding.",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".... | // Receive receives one or more messages from netlink. Multi-part messages are
// handled transparently and returned as a single slice of Messages, with the
// final empty "multi-part done" message removed.
//
// If any of the messages indicate a netlink error, that error will be returned. | [
"Receive",
"receives",
"one",
"or",
"more",
"messages",
"from",
"netlink",
".",
"Multi",
"-",
"part",
"messages",
"are",
"handled",
"transparently",
"and",
"returned",
"as",
"a",
"single",
"slice",
"of",
"Messages",
"with",
"the",
"final",
"empty",
"multi",
... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L231-L237 |
19,371 | mdlayher/netlink | conn.go | lockedReceive | func (c *Conn) lockedReceive() ([]Message, error) {
msgs, err := c.receive()
if err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "recv: err: %v", err)
})
return nil, err
}
c.debug(func(d *debugger) {
for _, m := range msgs {
d.debugf(1, "recv: %+v", m)
}
})
// When using nltest, it's possible for zero messages to be returned by receive.
if len(msgs) == 0 {
return msgs, nil
}
// Trim the final message with multi-part done indicator if
// present.
if m := msgs[len(msgs)-1]; m.Header.Flags&Multi != 0 && m.Header.Type == Done {
return msgs[:len(msgs)-1], nil
}
return msgs, nil
} | go | func (c *Conn) lockedReceive() ([]Message, error) {
msgs, err := c.receive()
if err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "recv: err: %v", err)
})
return nil, err
}
c.debug(func(d *debugger) {
for _, m := range msgs {
d.debugf(1, "recv: %+v", m)
}
})
// When using nltest, it's possible for zero messages to be returned by receive.
if len(msgs) == 0 {
return msgs, nil
}
// Trim the final message with multi-part done indicator if
// present.
if m := msgs[len(msgs)-1]; m.Header.Flags&Multi != 0 && m.Header.Type == Done {
return msgs[:len(msgs)-1], nil
}
return msgs, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"lockedReceive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"msgs",
",",
"err",
":=",
"c",
".",
"receive",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"debug",
"(",
"func",
"("... | // lockedReceive implements Receive, but must be called with c.mu acquired for reading.
// We rely on the kernel to deal with concurrent reads and writes to the netlink
// socket itself. | [
"lockedReceive",
"implements",
"Receive",
"but",
"must",
"be",
"called",
"with",
"c",
".",
"mu",
"acquired",
"for",
"reading",
".",
"We",
"rely",
"on",
"the",
"kernel",
"to",
"deal",
"with",
"concurrent",
"reads",
"and",
"writes",
"to",
"the",
"netlink",
"... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L242-L270 |
19,372 | mdlayher/netlink | conn.go | receive | func (c *Conn) receive() ([]Message, error) {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
//
// This contract also applies to functions called within this function,
// such as checkMessage.
var res []Message
for {
msgs, err := c.sock.Receive()
if err != nil {
return nil, newOpError("receive", err)
}
// If this message is multi-part, we will need to perform an recursive call
// to continue draining the socket
var multi bool
for _, m := range msgs {
if err := checkMessage(m); err != nil {
return nil, err
}
// Does this message indicate a multi-part message?
if m.Header.Flags&Multi == 0 {
// No, check the next messages.
continue
}
// Does this message indicate the last message in a series of
// multi-part messages from a single read?
multi = m.Header.Type != Done
}
res = append(res, msgs...)
if !multi {
// No more messages coming.
return res, nil
}
}
} | go | func (c *Conn) receive() ([]Message, error) {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
//
// This contract also applies to functions called within this function,
// such as checkMessage.
var res []Message
for {
msgs, err := c.sock.Receive()
if err != nil {
return nil, newOpError("receive", err)
}
// If this message is multi-part, we will need to perform an recursive call
// to continue draining the socket
var multi bool
for _, m := range msgs {
if err := checkMessage(m); err != nil {
return nil, err
}
// Does this message indicate a multi-part message?
if m.Header.Flags&Multi == 0 {
// No, check the next messages.
continue
}
// Does this message indicate the last message in a series of
// multi-part messages from a single read?
multi = m.Header.Type != Done
}
res = append(res, msgs...)
if !multi {
// No more messages coming.
return res, nil
}
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"receive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"// NB: All non-nil errors returned from this function *must* be of type",
"// OpError in order to maintain the appropriate contract with callers of",
"// this package.",
... | // receive is the internal implementation of Conn.Receive, which can be called
// recursively to handle multi-part messages. | [
"receive",
"is",
"the",
"internal",
"implementation",
"of",
"Conn",
".",
"Receive",
"which",
"can",
"be",
"called",
"recursively",
"to",
"handle",
"multi",
"-",
"part",
"messages",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L274-L316 |
19,373 | mdlayher/netlink | conn.go | JoinGroup | func (c *Conn) JoinGroup(group uint32) error {
conn, ok := c.sock.(groupJoinLeaver)
if !ok {
return notSupported("join-group")
}
return newOpError("join-group", conn.JoinGroup(group))
} | go | func (c *Conn) JoinGroup(group uint32) error {
conn, ok := c.sock.(groupJoinLeaver)
if !ok {
return notSupported("join-group")
}
return newOpError("join-group", conn.JoinGroup(group))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"JoinGroup",
"(",
"group",
"uint32",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"groupJoinLeaver",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"(",
"\"",
"\"",
")",
"... | // JoinGroup joins a netlink multicast group by its ID. | [
"JoinGroup",
"joins",
"a",
"netlink",
"multicast",
"group",
"by",
"its",
"ID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L327-L334 |
19,374 | mdlayher/netlink | conn.go | SetBPF | func (c *Conn) SetBPF(filter []bpf.RawInstruction) error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("set-bpf")
}
return newOpError("set-bpf", conn.SetBPF(filter))
} | go | func (c *Conn) SetBPF(filter []bpf.RawInstruction) error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("set-bpf")
}
return newOpError("set-bpf", conn.SetBPF(filter))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetBPF",
"(",
"filter",
"[",
"]",
"bpf",
".",
"RawInstruction",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"bpfSetter",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"... | // SetBPF attaches an assembled BPF program to a Conn. | [
"SetBPF",
"attaches",
"an",
"assembled",
"BPF",
"program",
"to",
"a",
"Conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L354-L361 |
19,375 | mdlayher/netlink | conn.go | RemoveBPF | func (c *Conn) RemoveBPF() error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("remove-bpf")
}
return newOpError("remove-bpf", conn.RemoveBPF())
} | go | func (c *Conn) RemoveBPF() error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("remove-bpf")
}
return newOpError("remove-bpf", conn.RemoveBPF())
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"RemoveBPF",
"(",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"bpfSetter",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"retu... | // RemoveBPF removes a BPF filter from a Conn. | [
"RemoveBPF",
"removes",
"a",
"BPF",
"filter",
"from",
"a",
"Conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L364-L371 |
19,376 | mdlayher/netlink | conn.go | SetDeadline | func (c *Conn) SetDeadline(t time.Time) error {
conn, ok := c.sock.(deadlineSetter)
if !ok {
return notSupported("set-deadline")
}
return newOpError("set-deadline", conn.SetDeadline(t))
} | go | func (c *Conn) SetDeadline(t time.Time) error {
conn, ok := c.sock.(deadlineSetter)
if !ok {
return notSupported("set-deadline")
}
return newOpError("set-deadline", conn.SetDeadline(t))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"deadlineSetter",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"(",
"\"",
"\""... | // SetDeadline sets the read and write deadlines associated with the connection.
//
// Deadline functionality is only supported on Go 1.12+. Calling this function
// on older versions of Go will result in an error. | [
"SetDeadline",
"sets",
"the",
"read",
"and",
"write",
"deadlines",
"associated",
"with",
"the",
"connection",
".",
"Deadline",
"functionality",
"is",
"only",
"supported",
"on",
"Go",
"1",
".",
"12",
"+",
".",
"Calling",
"this",
"function",
"on",
"older",
"ve... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L385-L392 |
19,377 | mdlayher/netlink | conn.go | fixMsg | func (c *Conn) fixMsg(m *Message, ml int) {
if m.Header.Length == 0 {
m.Header.Length = uint32(nlmsgAlign(ml))
}
if m.Header.Sequence == 0 {
m.Header.Sequence = c.nextSequence()
}
if m.Header.PID == 0 {
m.Header.PID = c.pid
}
} | go | func (c *Conn) fixMsg(m *Message, ml int) {
if m.Header.Length == 0 {
m.Header.Length = uint32(nlmsgAlign(ml))
}
if m.Header.Sequence == 0 {
m.Header.Sequence = c.nextSequence()
}
if m.Header.PID == 0 {
m.Header.PID = c.pid
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"fixMsg",
"(",
"m",
"*",
"Message",
",",
"ml",
"int",
")",
"{",
"if",
"m",
".",
"Header",
".",
"Length",
"==",
"0",
"{",
"m",
".",
"Header",
".",
"Length",
"=",
"uint32",
"(",
"nlmsgAlign",
"(",
"ml",
")",
... | // fixMsg updates the fields of m using the logic specified in Send. | [
"fixMsg",
"updates",
"the",
"fields",
"of",
"m",
"using",
"the",
"logic",
"specified",
"in",
"Send",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L513-L525 |
19,378 | mdlayher/netlink | conn.go | Validate | func Validate(request Message, replies []Message) error {
for _, m := range replies {
// Check for mismatched sequence, unless:
// - request had no sequence, meaning we are probably validating
// a multicast reply
if m.Header.Sequence != request.Header.Sequence && request.Header.Sequence != 0 {
return newOpError("validate", errMismatchedSequence)
}
// Check for mismatched PID, unless:
// - request had no PID, meaning we are either:
// - validating a multicast reply
// - netlink has not yet assigned us a PID
// - response had no PID, meaning it's from the kernel as a multicast reply
if m.Header.PID != request.Header.PID && request.Header.PID != 0 && m.Header.PID != 0 {
return newOpError("validate", errMismatchedPID)
}
}
return nil
} | go | func Validate(request Message, replies []Message) error {
for _, m := range replies {
// Check for mismatched sequence, unless:
// - request had no sequence, meaning we are probably validating
// a multicast reply
if m.Header.Sequence != request.Header.Sequence && request.Header.Sequence != 0 {
return newOpError("validate", errMismatchedSequence)
}
// Check for mismatched PID, unless:
// - request had no PID, meaning we are either:
// - validating a multicast reply
// - netlink has not yet assigned us a PID
// - response had no PID, meaning it's from the kernel as a multicast reply
if m.Header.PID != request.Header.PID && request.Header.PID != 0 && m.Header.PID != 0 {
return newOpError("validate", errMismatchedPID)
}
}
return nil
} | [
"func",
"Validate",
"(",
"request",
"Message",
",",
"replies",
"[",
"]",
"Message",
")",
"error",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"replies",
"{",
"// Check for mismatched sequence, unless:",
"// - request had no sequence, meaning we are probably validating",
... | // Validate validates one or more reply Messages against a request Message,
// ensuring that they contain matching sequence numbers and PIDs. | [
"Validate",
"validates",
"one",
"or",
"more",
"reply",
"Messages",
"against",
"a",
"request",
"Message",
"ensuring",
"that",
"they",
"contain",
"matching",
"sequence",
"numbers",
"and",
"PIDs",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L535-L555 |
19,379 | mdlayher/netlink | errors.go | IsNotExist | func IsNotExist(err error) bool {
switch err := err.(type) {
case *OpError:
// TODO(mdlayher): more error handling logic?
// Unwrap the inner error and use the stdlib's logic.
return os.IsNotExist(err.Err)
default:
return os.IsNotExist(err)
}
} | go | func IsNotExist(err error) bool {
switch err := err.(type) {
case *OpError:
// TODO(mdlayher): more error handling logic?
// Unwrap the inner error and use the stdlib's logic.
return os.IsNotExist(err.Err)
default:
return os.IsNotExist(err)
}
} | [
"func",
"IsNotExist",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"OpError",
":",
"// TODO(mdlayher): more error handling logic?",
"// Unwrap the inner error and use the stdlib's logic.",
"return",
"os"... | // IsNotExist determines if an error is produced as the result of querying some
// file, object, resource, etc. which does not exist. Users of this package
// should always use netlink.IsNotExist, rather than os.IsNotExist, when
// checking for specific netlink-related errors.
//
// Errors types created by this package, such as OpError, can be used with
// IsNotExist, but this function also defers to the behavior of os.IsNotExist
// for unrecognized error types. | [
"IsNotExist",
"determines",
"if",
"an",
"error",
"is",
"produced",
"as",
"the",
"result",
"of",
"querying",
"some",
"file",
"object",
"resource",
"etc",
".",
"which",
"does",
"not",
"exist",
".",
"Users",
"of",
"this",
"package",
"should",
"always",
"use",
... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/errors.go#L35-L45 |
19,380 | mdlayher/netlink | errors.go | Temporary | func (e *OpError) Temporary() bool {
if ne, ok := e.Err.(*os.SyscallError); ok {
t, ok := ne.Err.(temporary)
return ok && t.Temporary()
}
t, ok := e.Err.(temporary)
return ok && t.Temporary()
} | go | func (e *OpError) Temporary() bool {
if ne, ok := e.Err.(*os.SyscallError); ok {
t, ok := ne.Err.(temporary)
return ok && t.Temporary()
}
t, ok := e.Err.(temporary)
return ok && t.Temporary()
} | [
"func",
"(",
"e",
"*",
"OpError",
")",
"Temporary",
"(",
")",
"bool",
"{",
"if",
"ne",
",",
"ok",
":=",
"e",
".",
"Err",
".",
"(",
"*",
"os",
".",
"SyscallError",
")",
";",
"ok",
"{",
"t",
",",
"ok",
":=",
"ne",
".",
"Err",
".",
"(",
"tempo... | // Temporary reports whether an operation may succeed if retried. | [
"Temporary",
"reports",
"whether",
"an",
"operation",
"may",
"succeed",
"if",
"retried",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/errors.go#L112-L119 |
19,381 | mdlayher/netlink | netns_linux.go | setThreadNetNS | func setThreadNetNS(fd int) error {
return os.NewSyscallError("setns", unix.Setns(fd, unix.CLONE_NEWNET))
} | go | func setThreadNetNS(fd int) error {
return os.NewSyscallError("setns", unix.Setns(fd, unix.CLONE_NEWNET))
} | [
"func",
"setThreadNetNS",
"(",
"fd",
"int",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"unix",
".",
"Setns",
"(",
"fd",
",",
"unix",
".",
"CLONE_NEWNET",
")",
")",
"\n",
"}"
] | // setThreadNetNS sets the network namespace of the thread of the current goroutine to
// the namespace described by the user-provided file descriptor. | [
"setThreadNetNS",
"sets",
"the",
"network",
"namespace",
"of",
"the",
"thread",
"of",
"the",
"current",
"goroutine",
"to",
"the",
"namespace",
"described",
"by",
"the",
"user",
"-",
"provided",
"file",
"descriptor",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/netns_linux.go#L25-L27 |
19,382 | mdlayher/netlink | conn_linux.go | dial | func dial(family int, config *Config) (*conn, uint32, error) {
// Prepare sysSocket's internal loop and create the socket.
//
// The conditional is inverted because a zero value of false is desired
// if no config, but it's easier to interpret within this code when the
// value is inverted.
if config == nil {
config = &Config{}
}
sock, err := newSysSocket(config)
if err != nil {
return nil, 0, err
}
if err := sock.Socket(family); err != nil {
return nil, 0, os.NewSyscallError("socket", err)
}
return bind(sock, config)
} | go | func dial(family int, config *Config) (*conn, uint32, error) {
// Prepare sysSocket's internal loop and create the socket.
//
// The conditional is inverted because a zero value of false is desired
// if no config, but it's easier to interpret within this code when the
// value is inverted.
if config == nil {
config = &Config{}
}
sock, err := newSysSocket(config)
if err != nil {
return nil, 0, err
}
if err := sock.Socket(family); err != nil {
return nil, 0, os.NewSyscallError("socket", err)
}
return bind(sock, config)
} | [
"func",
"dial",
"(",
"family",
"int",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"conn",
",",
"uint32",
",",
"error",
")",
"{",
"// Prepare sysSocket's internal loop and create the socket.",
"//",
"// The conditional is inverted because a zero value of false is desired",
... | // dial is the entry point for Dial. dial opens a netlink socket using
// system calls, and returns its PID. | [
"dial",
"is",
"the",
"entry",
"point",
"for",
"Dial",
".",
"dial",
"opens",
"a",
"netlink",
"socket",
"using",
"system",
"calls",
"and",
"returns",
"its",
"PID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L49-L69 |
19,383 | mdlayher/netlink | conn_linux.go | bind | func bind(s socket, config *Config) (*conn, uint32, error) {
if config == nil {
config = &Config{}
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
Groups: config.Groups,
}
// Socket must be closed in the event of any system call errors, to avoid
// leaking file descriptors.
if err := s.Bind(addr); err != nil {
_ = s.Close()
return nil, 0, os.NewSyscallError("bind", err)
}
sa, err := s.Getsockname()
if err != nil {
_ = s.Close()
return nil, 0, os.NewSyscallError("getsockname", err)
}
pid := sa.(*unix.SockaddrNetlink).Pid
return &conn{
s: s,
sa: addr,
}, pid, nil
} | go | func bind(s socket, config *Config) (*conn, uint32, error) {
if config == nil {
config = &Config{}
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
Groups: config.Groups,
}
// Socket must be closed in the event of any system call errors, to avoid
// leaking file descriptors.
if err := s.Bind(addr); err != nil {
_ = s.Close()
return nil, 0, os.NewSyscallError("bind", err)
}
sa, err := s.Getsockname()
if err != nil {
_ = s.Close()
return nil, 0, os.NewSyscallError("getsockname", err)
}
pid := sa.(*unix.SockaddrNetlink).Pid
return &conn{
s: s,
sa: addr,
}, pid, nil
} | [
"func",
"bind",
"(",
"s",
"socket",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"conn",
",",
"uint32",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"config",
"=",
"&",
"Config",
"{",
"}",
"\n",
"}",
"\n\n",
"addr",
":=",
"&",
"uni... | // bind binds a connection to netlink using the input socket, which may be
// a system call implementation or a mocked one for tests. | [
"bind",
"binds",
"a",
"connection",
"to",
"netlink",
"using",
"the",
"input",
"socket",
"which",
"may",
"be",
"a",
"system",
"call",
"implementation",
"or",
"a",
"mocked",
"one",
"for",
"tests",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L73-L103 |
19,384 | mdlayher/netlink | conn_linux.go | SendMessages | func (c *conn) SendMessages(messages []Message) error {
var buf []byte
for _, m := range messages {
b, err := m.MarshalBinary()
if err != nil {
return err
}
buf = append(buf, b...)
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(buf, nil, addr, 0))
} | go | func (c *conn) SendMessages(messages []Message) error {
var buf []byte
for _, m := range messages {
b, err := m.MarshalBinary()
if err != nil {
return err
}
buf = append(buf, b...)
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(buf, nil, addr, 0))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"SendMessages",
"(",
"messages",
"[",
"]",
"Message",
")",
"error",
"{",
"var",
"buf",
"[",
"]",
"byte",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"messages",
"{",
"b",
",",
"err",
":=",
"m",
".",
"MarshalBina... | // SendMessages serializes multiple Messages and sends them to netlink. | [
"SendMessages",
"serializes",
"multiple",
"Messages",
"and",
"sends",
"them",
"to",
"netlink",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L106-L122 |
19,385 | mdlayher/netlink | conn_linux.go | Send | func (c *conn) Send(m Message) error {
b, err := m.MarshalBinary()
if err != nil {
return err
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(b, nil, addr, 0))
} | go | func (c *conn) Send(m Message) error {
b, err := m.MarshalBinary()
if err != nil {
return err
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(b, nil, addr, 0))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"Send",
"(",
"m",
"Message",
")",
"error",
"{",
"b",
",",
"err",
":=",
"m",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"addr",
":=",
"&",
"unix",
... | // Send sends a single Message to netlink. | [
"Send",
"sends",
"a",
"single",
"Message",
"to",
"netlink",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L125-L136 |
19,386 | mdlayher/netlink | conn_linux.go | Receive | func (c *conn) Receive() ([]Message, error) {
b := make([]byte, os.Getpagesize())
for {
// Peek at the buffer to see how many bytes are available.
//
// TODO(mdlayher): deal with OOB message data if available, such as
// when PacketInfo ConnOption is true.
n, _, _, _, err := c.s.Recvmsg(b, nil, unix.MSG_PEEK)
if err != nil {
return nil, os.NewSyscallError("recvmsg", err)
}
// Break when we can read all messages
if n < len(b) {
break
}
// Double in size if not enough bytes
b = make([]byte, len(b)*2)
}
// Read out all available messages
n, _, _, _, err := c.s.Recvmsg(b, nil, 0)
if err != nil {
return nil, os.NewSyscallError("recvmsg", err)
}
n = nlmsgAlign(n)
raw, err := syscall.ParseNetlinkMessage(b[:n])
if err != nil {
return nil, err
}
msgs := make([]Message, 0, len(raw))
for _, r := range raw {
m := Message{
Header: sysToHeader(r.Header),
Data: r.Data,
}
msgs = append(msgs, m)
}
return msgs, nil
} | go | func (c *conn) Receive() ([]Message, error) {
b := make([]byte, os.Getpagesize())
for {
// Peek at the buffer to see how many bytes are available.
//
// TODO(mdlayher): deal with OOB message data if available, such as
// when PacketInfo ConnOption is true.
n, _, _, _, err := c.s.Recvmsg(b, nil, unix.MSG_PEEK)
if err != nil {
return nil, os.NewSyscallError("recvmsg", err)
}
// Break when we can read all messages
if n < len(b) {
break
}
// Double in size if not enough bytes
b = make([]byte, len(b)*2)
}
// Read out all available messages
n, _, _, _, err := c.s.Recvmsg(b, nil, 0)
if err != nil {
return nil, os.NewSyscallError("recvmsg", err)
}
n = nlmsgAlign(n)
raw, err := syscall.ParseNetlinkMessage(b[:n])
if err != nil {
return nil, err
}
msgs := make([]Message, 0, len(raw))
for _, r := range raw {
m := Message{
Header: sysToHeader(r.Header),
Data: r.Data,
}
msgs = append(msgs, m)
}
return msgs, nil
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"Receive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"os",
".",
"Getpagesize",
"(",
")",
")",
"\n",
"for",
"{",
"// Peek at the buffer to see how m... | // Receive receives one or more Messages from netlink. | [
"Receive",
"receives",
"one",
"or",
"more",
"Messages",
"from",
"netlink",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L139-L184 |
19,387 | mdlayher/netlink | conn_linux.go | JoinGroup | func (c *conn) JoinGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_ADD_MEMBERSHIP,
int(group),
))
} | go | func (c *conn) JoinGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_ADD_MEMBERSHIP,
int(group),
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"JoinGroup",
"(",
"group",
"uint32",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_NETLINK",
",",
"unix",
".",
"NETLINK... | // JoinGroup joins a multicast group by ID. | [
"JoinGroup",
"joins",
"a",
"multicast",
"group",
"by",
"ID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L202-L208 |
19,388 | mdlayher/netlink | conn_linux.go | LeaveGroup | func (c *conn) LeaveGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_DROP_MEMBERSHIP,
int(group),
))
} | go | func (c *conn) LeaveGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_DROP_MEMBERSHIP,
int(group),
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"LeaveGroup",
"(",
"group",
"uint32",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_NETLINK",
",",
"unix",
".",
"NETLIN... | // LeaveGroup leaves a multicast group by ID. | [
"LeaveGroup",
"leaves",
"a",
"multicast",
"group",
"by",
"ID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L211-L217 |
19,389 | mdlayher/netlink | conn_linux.go | SetBPF | func (c *conn) SetBPF(filter []bpf.RawInstruction) error {
prog := unix.SockFprog{
Len: uint16(len(filter)),
Filter: (*unix.SockFilter)(unsafe.Pointer(&filter[0])),
}
return os.NewSyscallError("setsockopt", c.s.SetSockoptSockFprog(
unix.SOL_SOCKET,
unix.SO_ATTACH_FILTER,
&prog,
))
} | go | func (c *conn) SetBPF(filter []bpf.RawInstruction) error {
prog := unix.SockFprog{
Len: uint16(len(filter)),
Filter: (*unix.SockFilter)(unsafe.Pointer(&filter[0])),
}
return os.NewSyscallError("setsockopt", c.s.SetSockoptSockFprog(
unix.SOL_SOCKET,
unix.SO_ATTACH_FILTER,
&prog,
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"SetBPF",
"(",
"filter",
"[",
"]",
"bpf",
".",
"RawInstruction",
")",
"error",
"{",
"prog",
":=",
"unix",
".",
"SockFprog",
"{",
"Len",
":",
"uint16",
"(",
"len",
"(",
"filter",
")",
")",
",",
"Filter",
":",
"(... | // SetBPF attaches an assembled BPF program to a conn. | [
"SetBPF",
"attaches",
"an",
"assembled",
"BPF",
"program",
"to",
"a",
"conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L220-L231 |
19,390 | mdlayher/netlink | conn_linux.go | RemoveBPF | func (c *conn) RemoveBPF() error {
// 0 argument is ignored by SO_DETACH_FILTER.
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_DETACH_FILTER,
0,
))
} | go | func (c *conn) RemoveBPF() error {
// 0 argument is ignored by SO_DETACH_FILTER.
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_DETACH_FILTER,
0,
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"RemoveBPF",
"(",
")",
"error",
"{",
"// 0 argument is ignored by SO_DETACH_FILTER.",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_SOCKET",
",",
... | // RemoveBPF removes a BPF filter from a conn. | [
"RemoveBPF",
"removes",
"a",
"BPF",
"filter",
"from",
"a",
"conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L234-L241 |
19,391 | mdlayher/netlink | conn_linux.go | SetWriteBuffer | func (c *conn) SetWriteBuffer(bytes int) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_SNDBUF,
bytes,
))
} | go | func (c *conn) SetWriteBuffer(bytes int) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_SNDBUF,
bytes,
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"SetWriteBuffer",
"(",
"bytes",
"int",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_SOCKET",
",",
"unix",
".",
"SO_SND... | // SetReadBuffer sets the size of the operating system's transmit buffer
// associated with the Conn. | [
"SetReadBuffer",
"sets",
"the",
"size",
"of",
"the",
"operating",
"system",
"s",
"transmit",
"buffer",
"associated",
"with",
"the",
"Conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L287-L293 |
19,392 | mdlayher/netlink | conn_linux.go | linuxOption | func linuxOption(o ConnOption) (int, bool) {
switch o {
case PacketInfo:
return unix.NETLINK_PKTINFO, true
case BroadcastError:
return unix.NETLINK_BROADCAST_ERROR, true
case NoENOBUFS:
return unix.NETLINK_NO_ENOBUFS, true
case ListenAllNSID:
return unix.NETLINK_LISTEN_ALL_NSID, true
case CapAcknowledge:
return unix.NETLINK_CAP_ACK, true
default:
return 0, false
}
} | go | func linuxOption(o ConnOption) (int, bool) {
switch o {
case PacketInfo:
return unix.NETLINK_PKTINFO, true
case BroadcastError:
return unix.NETLINK_BROADCAST_ERROR, true
case NoENOBUFS:
return unix.NETLINK_NO_ENOBUFS, true
case ListenAllNSID:
return unix.NETLINK_LISTEN_ALL_NSID, true
case CapAcknowledge:
return unix.NETLINK_CAP_ACK, true
default:
return 0, false
}
} | [
"func",
"linuxOption",
"(",
"o",
"ConnOption",
")",
"(",
"int",
",",
"bool",
")",
"{",
"switch",
"o",
"{",
"case",
"PacketInfo",
":",
"return",
"unix",
".",
"NETLINK_PKTINFO",
",",
"true",
"\n",
"case",
"BroadcastError",
":",
"return",
"unix",
".",
"NETL... | // linuxOption converts a ConnOption to its Linux value. | [
"linuxOption",
"converts",
"a",
"ConnOption",
"to",
"its",
"Linux",
"value",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L296-L311 |
19,393 | mdlayher/netlink | conn_linux.go | newSysSocket | func newSysSocket(config *Config) (*sysSocket, error) {
g, err := newLockedNetNSGoroutine(config.NetNS)
if err != nil {
return nil, err
}
return &sysSocket{
g: g,
}, nil
} | go | func newSysSocket(config *Config) (*sysSocket, error) {
g, err := newLockedNetNSGoroutine(config.NetNS)
if err != nil {
return nil, err
}
return &sysSocket{
g: g,
}, nil
} | [
"func",
"newSysSocket",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"sysSocket",
",",
"error",
")",
"{",
"g",
",",
"err",
":=",
"newLockedNetNSGoroutine",
"(",
"config",
".",
"NetNS",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"... | // newSysSocket creates a sysSocket that optionally locks its internal goroutine
// to a single thread. | [
"newSysSocket",
"creates",
"a",
"sysSocket",
"that",
"optionally",
"locks",
"its",
"internal",
"goroutine",
"to",
"a",
"single",
"thread",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L338-L346 |
19,394 | mdlayher/netlink | conn_linux.go | do | func (s *sysSocket) do(f func()) error {
// All operations handled by this function are assumed to only
// read from s.done.
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
s.g.run(f)
return nil
} | go | func (s *sysSocket) do(f func()) error {
// All operations handled by this function are assumed to only
// read from s.done.
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
s.g.run(f)
return nil
} | [
"func",
"(",
"s",
"*",
"sysSocket",
")",
"do",
"(",
"f",
"func",
"(",
")",
")",
"error",
"{",
"// All operations handled by this function are assumed to only",
"// read from s.done.",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
"."... | // do runs f in a worker goroutine which can be locked to one thread. | [
"do",
"runs",
"f",
"in",
"a",
"worker",
"goroutine",
"which",
"can",
"be",
"locked",
"to",
"one",
"thread",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L349-L361 |
19,395 | mdlayher/netlink | conn_linux.go | read | func (s *sysSocket) read(f func(fd int) bool) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdread(s.fd, f)
})
return err
} | go | func (s *sysSocket) read(f func(fd int) bool) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdread(s.fd, f)
})
return err
} | [
"func",
"(",
"s",
"*",
"sysSocket",
")",
"read",
"(",
"f",
"func",
"(",
"fd",
"int",
")",
"bool",
")",
"error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"c... | // read executes f, a read function, against the associated file descriptor. | [
"read",
"executes",
"f",
"a",
"read",
"function",
"against",
"the",
"associated",
"file",
"descriptor",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L364-L377 |
19,396 | mdlayher/netlink | conn_linux.go | control | func (s *sysSocket) control(f func(fd int)) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdcontrol(s.fd, f)
})
return err
} | go | func (s *sysSocket) control(f func(fd int)) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdcontrol(s.fd, f)
})
return err
} | [
"func",
"(",
"s",
"*",
"sysSocket",
")",
"control",
"(",
"f",
"func",
"(",
"fd",
"int",
")",
")",
"error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"closed",... | // control executes f, a control function, against the associated file descriptor. | [
"control",
"executes",
"f",
"a",
"control",
"function",
"against",
"the",
"associated",
"file",
"descriptor",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L396-L409 |
19,397 | mdlayher/netlink | conn_linux.go | run | func (g *lockedNetNSGoroutine) run(f func()) {
done := make(chan struct{})
g.funcC <- func() {
defer close(done)
f()
}
<-done
} | go | func (g *lockedNetNSGoroutine) run(f func()) {
done := make(chan struct{})
g.funcC <- func() {
defer close(done)
f()
}
<-done
} | [
"func",
"(",
"g",
"*",
"lockedNetNSGoroutine",
")",
"run",
"(",
"f",
"func",
"(",
")",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"g",
".",
"funcC",
"<-",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"done",
")... | // run runs f on the worker goroutine. | [
"run",
"runs",
"f",
"on",
"the",
"worker",
"goroutine",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L670-L677 |
19,398 | looplab/eventhorizon | repo/version/repo.go | Find | func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error) {
// If there is no min version set just return the item as normally.
minVersion, ok := eh.MinVersionFromContext(ctx)
if !ok || minVersion < 1 {
return r.ReadWriteRepo.Find(ctx, id)
}
// Try to get the correct version, retry with exponentially longer intervals
// until the deadline expires. If there is no deadline just try once.
delay := &backoff.Backoff{}
_, hasDeadline := ctx.Deadline()
for {
entity, err := r.findMinVersion(ctx, id, minVersion)
if rrErr, ok := err.(eh.RepoError); ok &&
(rrErr.Err == eh.ErrIncorrectEntityVersion || rrErr.Err == eh.ErrEntityNotFound) {
// Try again for incorrect version or if the entity was not found.
} else if err != nil {
// Return any real error.
return nil, err
} else {
// Return the entity.
return entity, nil
}
// If there is no deadline, return whatever we have at this point.
if !hasDeadline {
return entity, err
}
select {
case <-time.After(delay.Duration()):
case <-ctx.Done():
return nil, ctx.Err()
}
}
} | go | func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error) {
// If there is no min version set just return the item as normally.
minVersion, ok := eh.MinVersionFromContext(ctx)
if !ok || minVersion < 1 {
return r.ReadWriteRepo.Find(ctx, id)
}
// Try to get the correct version, retry with exponentially longer intervals
// until the deadline expires. If there is no deadline just try once.
delay := &backoff.Backoff{}
_, hasDeadline := ctx.Deadline()
for {
entity, err := r.findMinVersion(ctx, id, minVersion)
if rrErr, ok := err.(eh.RepoError); ok &&
(rrErr.Err == eh.ErrIncorrectEntityVersion || rrErr.Err == eh.ErrEntityNotFound) {
// Try again for incorrect version or if the entity was not found.
} else if err != nil {
// Return any real error.
return nil, err
} else {
// Return the entity.
return entity, nil
}
// If there is no deadline, return whatever we have at this point.
if !hasDeadline {
return entity, err
}
select {
case <-time.After(delay.Duration()):
case <-ctx.Done():
return nil, ctx.Err()
}
}
} | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Find",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"uuid",
".",
"UUID",
")",
"(",
"eh",
".",
"Entity",
",",
"error",
")",
"{",
"// If there is no min version set just return the item as normally.",
"minVersion",
",",
... | // Find implements the Find method of the eventhorizon.ReadModel interface.
// If the context contains a min version set by WithMinVersion it will only
// return an item if its version is at least min version. If a timeout or
// deadline is set on the context it will repetedly try to get the item until
// either the version matches or the deadline is reached. | [
"Find",
"implements",
"the",
"Find",
"method",
"of",
"the",
"eventhorizon",
".",
"ReadModel",
"interface",
".",
"If",
"the",
"context",
"contains",
"a",
"min",
"version",
"set",
"by",
"WithMinVersion",
"it",
"will",
"only",
"return",
"an",
"item",
"if",
"its... | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/version/repo.go#L48-L83 |
19,399 | looplab/eventhorizon | repo/version/repo.go | findMinVersion | func (r *Repo) findMinVersion(ctx context.Context, id uuid.UUID, minVersion int) (eh.Entity, error) {
entity, err := r.ReadWriteRepo.Find(ctx, id)
if err != nil {
return nil, err
}
versionable, ok := entity.(eh.Versionable)
if !ok {
return nil, eh.RepoError{
Err: eh.ErrEntityHasNoVersion,
Namespace: eh.NamespaceFromContext(ctx),
}
}
if versionable.AggregateVersion() < minVersion {
return nil, eh.RepoError{
Err: eh.ErrIncorrectEntityVersion,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return entity, nil
} | go | func (r *Repo) findMinVersion(ctx context.Context, id uuid.UUID, minVersion int) (eh.Entity, error) {
entity, err := r.ReadWriteRepo.Find(ctx, id)
if err != nil {
return nil, err
}
versionable, ok := entity.(eh.Versionable)
if !ok {
return nil, eh.RepoError{
Err: eh.ErrEntityHasNoVersion,
Namespace: eh.NamespaceFromContext(ctx),
}
}
if versionable.AggregateVersion() < minVersion {
return nil, eh.RepoError{
Err: eh.ErrIncorrectEntityVersion,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return entity, nil
} | [
"func",
"(",
"r",
"*",
"Repo",
")",
"findMinVersion",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"uuid",
".",
"UUID",
",",
"minVersion",
"int",
")",
"(",
"eh",
".",
"Entity",
",",
"error",
")",
"{",
"entity",
",",
"err",
":=",
"r",
".",
"R... | // findMinVersion finds an item if it has a version and it is at least minVersion. | [
"findMinVersion",
"finds",
"an",
"item",
"if",
"it",
"has",
"a",
"version",
"and",
"it",
"is",
"at",
"least",
"minVersion",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/version/repo.go#L86-L108 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.